Slippers and Perl - Fortune [possible satire]

mstfrikinz: but you're welcome to ignore us, just come back for your "I told you so" when the penny finally drops :D
rindolfbuu: define penny finally drops
rindolfbuubot: define penny finally drops
buubotrindolf: penny n 1: a fractional monetary unit of Ireland and the United Kingdom; equal to one hundredth of a pound 2: a coin worth one-hundredth of the value of the basic unit [syn: {cent}, {centime}] [also: {pence} (pl)]
dngorfrikinz: Reflex is still pretty raw, but it's eventy without so much loopy.
rindolfIn Hebrew we say "The phone token has fallen" instead of "the penny finally drops".
dngorIs that related to "the other shoe has dropped"?
rindolfdngor: well, it means the same thing as the English expression - "I finally got to the bottom of it."
rindolfOr understood it.
dngorOh, they're completely different idioms.
* mstbeats dngor with a slipper
rindolfmst: :-D
Su-Sheekinky.
mstSu-Shee: wrt the topic ["Su-Shee wants the web-development framework that makes web-development hard, difficult and complicated"], it's called Maypole :)
rindolfmst: heh.
rindolfmst: yes, I can imagine that about Maypole.
Su-Sheemst, avar: thank you so much. ;)
Su-Sheeplease mail the sourcecode to rindolf who put it in the topic ;)
rindolfSu-Shee: I can CPAN it.
Su-Sheethe topic?
mutewitI have a string and am looking for a quick way to extract all 5-character slices out of it.
rindolfSu-Shee: :-)
rindolfIRC-Freenode-Perl-Topic-SuShee-WebDevelFrameworks-v0.0.1.tar.gz
mutewitFor example 'abcdef' returns 'abcde', 'bcdef'
mutewitAny suggestions?
rindolfmutewit: use subst
rindolfmutewit: use substr
rindolfmutewit: with a map
rindolfeval: my $long_str = "0123456789abcdefgh"; [map { substr($long_s, $_, $_+5 } (0 .. length($long_s)-5)]
buubotrindolf: ERROR: syntax error at (eval 36) line 1, at EOF
rindolfeval: my $long_str = "0123456789abcdefgh"; [map { substr($long_s, $_, $_+5) } (0 .. length($long_s)-5)]
buubotrindolf: []
mutewitrindolf: Awesome.
rindolfeval: my $long_s = "0123456789abcdefgh"; [map { substr($long_s, $_, $_+5) } (0 .. length($long_s)-5)]
buubotrindolf: ["01234", 123456, 2345678, "3456789a", "456789abc", "56789abcde", "6789abcdefg", "789abcdefgh", "89abcdefgh", "9abcdefgh", "abcdefgh", "bcdefgh", "cdefgh", "defgh"]
rindolfThrid time the charm!
mst... thrid
* rindolfhits buubot with a big strict pragma.
* mstturns the slipper on rindolf
rindolfmst: yes, my typing sucks today.
rindolfBut f**k it! IRC is not exactly the declaration of independence.
pragma_ow!
rindolfpragma_: pardon?
* rindolfhits pragma_ with mst's slipper so it will really hurt.
pragma_why are you hitting buubot with me?
rindolfpragma_: the strict pragma.
rindolfpragma_: not you.
rindolfperlbot: strict
perlbotrindolf: Perl strictures - http://perldoc.perl.org/strict.html
rindolfpragma_: ^^^
rindolfpragma_: we call the lowercase modules pragmata (sp?) in Perl.
rindolfhttp://en.wiktionary.org/wiki/Special:Search?search=pragmata - hmm....
rindolfI thought pragmata was a valid plural of pragma.
dngorow? ow!
mutewitrindolf: Are you sure that generates only strings of length 5?
rindolfmutewit: well, you need to watch from fencepost errors.
mstmutewit: hey, he got you half way there
rindolfmutewit: oh wait.
mstmutewit: how about you read p3rl.org/substr and p3rl.org/map and have a go yourself
rindolfmutewit: yes , you need substr($long_s, $_, 5)
mstmutewit: this is a help-you-to-learn channel
mstmutewit: not a "write your code for you" channel
rindolfmutewit: and beware from fencepost errors.
rindolflike substr($long_s , 1000, 5)
rindolfBecause that will be ""
rindolfOr a 4 chars length.
mutewitrindolf: I wanted the length argument to be 5 :p
mutewitmst: I understand, I just missed the $_ + 5 issue.
mstmutewit: right. what I'm saying is, you should have experimented
rindolfmutewit: yes, I know.
mstmutewit: then shown us the experiment and said "I can't work out why this is still wrong, here's what I've worked out so far"
mstmutewit: then we can help you learn
mstmutewit: assuming learning to write stuff yourself is what you're aiming for
* rindolfwaits for tybalt89 to come up with a funky regex to do it.
mst(if it isn't, please just throw yourself off a cliff or something, kthx ;)
rindolfmst: I think that's the case, no need to preach to mutewit about it.
mutewitmutewit: I did, and figured out the solution. when switching windows.
mstmutewit: aye. I'm just trying to explain how to get the most learning out of us as well as the most working code.
* rindolfsometimes thinks we spend much more IRC volume discussing netiquette than actually suffering from the bad netiquette.
mutewitBut by the time I came back to the channel there was a whole page of "preaching".
mutewitI was using a split method with array indexing and it felt too much like a C-approach.
rindolfmutewit: oh, you split the string into chars?
mstyeah, by the time you've done map, join, split, ...
mstyou've basically just reimplemented substr badly :)
mutewitrindolf: That's what I was doing, but the map/substr approach is a lot cleaner.
rindolfmutewit: yeah/
rindolfmutewit: split into chars sometimes has some uses.
rindolfmutewit: but this reminds me too much of SICP.
rindolfperlbot: sicp
perlbotrindolf: http://mitpress.mit.edu/sicp/ - "Structure and Interpretation of Computer Programs" - A Classical Text on Programming
rindolfmutewit: see - http://www.shlomifish.org/lecture/Perl/Lightning/Too-Many-Ways/slides/slide13.html
rindolfmutewit: this is how an SICP programmer will implement a simple text processing task.
mutewitSICP, love the book.
mutewitand all the OCaml work this year has given rise to a functional bent of mind
mutewitwhich is kinda screwing around with my perl code.
rindolfmutewit: yeah.
rindolfmutewit: http://www.shlomifish.org/lecture/Perl/Lightning/Too-Many-Ways/slides/slide12.html - this is the fastest Perl solution.
rindolfAt least in speed.
rindolfIt can be a little shorter with a regex lookahead, but it's less elegant and slower.
rindolfhttp://www.shlomifish.org/lecture/Perl/Lightning/Too-Many-Ways/slides/slide9.html - there you go.
rindolfmutewit: did you know how to program before reading SICP?
rindolfI think it's not a good introductory book.
rindolfMIT are going to ditch it in favour of some Python/Robotics curriculum.
mstI think it's only a good introductory book if you know some math and have the brain to follow it
mstit teaches a lot of hard concepts very quickly
Su-Sheemst: from a "I'm from the humanities department" point of view it's manageable. it's not easy, but everyone can work with it.
tybalt89eval: $_ = "0123456789abcdefgh"; [ /(?=(.{5}))/g ]
buubottybalt89: ["01234",12345,23456,34567,45678,56789,"6789a","789ab","89abc","9abcd","abcde","bcdef","cdefg","defgh"]
mutewitrindolf: Yes.
rindolfmutewit: ah. Using what?
rindolftybalt89++ # Up for the challenge.
mutewitand yes, MIT ditched SICP in favor of a Python-based intro course.
tybalt89rindolf: I was off in other windows :(
tybalt89mutewit: ^^ for 5 char slices
rindolfmutewit: don't use it if you want future generations to understand it.
* rindolfslaps tybalt89 with mst's slipper for golfing mutewit's solution and telling him it's a good idea.
tybalt89rindolf: that's not golfing, just common simple regex :)
rindolftybalt89: sigh.
rindolftybalt89: simple.
rindolfirregular regular expression.
rindolfMaybe use Regexp::Common
mutewitI added in tybalt89's code but commented it for future reference.
mstI'd definitely use the substr approach for real code
msttybalt89's code is cleverness to prove it can be done; I don't believe he was recommending it
tybalt89mst: sigh, yes, I am recommending it. It's the clearest solution.
msttybalt89: I respectfully disagree.
mstI find the substr approach far more obvious
Chazzrindolf, ty. :)
mstbut then, I mostly write applications perl rather than scripts, so I only engage in regexp cleverness when actively useful
rindolftybalt89: look-aheads and look-behinds are dark corners of the Perl not-so-reg-regexes
YaakovIn the context of this particular problem, it's pretty straightforward, but, knowledge of the development/maintenance team(s) would push my choce one way or another.
tybalt89mst: note it took rindolf three tries, and even then he got it wrong.
rindolftybalt89: well, I'm not focused now.
msttybalt89: map substr($str, $_, 5), 0 .. length($str)-5; ?
mstmaybe -6
* tybalt89turns the lens, trying to focus rindolf
rindolfmst: -5
mstbut it's hardly difficult; rindolf's just having a day of silly mistakes
rindolfUnit tests!
mstI'd expect him to get it right first time when on form too :)
rindolfSome clear code is hard to get right.
rindolfDoesn't make it less clear.
mstyeah
rindolfMost people will not write a correct binary search at first try.
tybalt89"maybe -6" is proof of lack of clarity. :)
rindolfBut the correct binary search is easy to digest.
msttybalt89: no, it's proof it's 8pm on a Sunday and I'm not particularly awake either
mstbut your code just made me go "hang on, WHAT?!"
mstthen I had to stop and dissect it
mst-then- I saw what you were doing
rindolfmst++
mstalso, the substr approach displays the semantics and the reasoning
mstwhereas the regex approach displays, well, line noise, frankly
rindolfmst: why don't we agree to disagree with tybalt89 ?
rindolfmst: so how's the weather? ;-)
Channel#perl
NetworkFreenode
TaglineSlippers and Perl
Published2010-04-09