Slippers and Perl - Fortune

Slippers and Perl

mst frikinz: but you're welcome to ignore us, just come back for your "I told you so" when the penny finally drops :D
rindolf buu: define penny finally drops
rindolf buubot: define penny finally drops
buubot rindolf: 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)]
dngor frikinz: Reflex is still pretty raw, but it's eventy without so much loopy.
rindolf In Hebrew we say "The phone token has fallen" instead of "the penny finally drops".
dngor Is that related to "the other shoe has dropped"?
rindolf dngor: well, it means the same thing as the English expression - "I finally got to the bottom of it."
rindolf Or understood it.
dngor Oh, they're completely different idioms.
* mst beats dngor with a slipper
rindolf mst: :-D
Su-Shee kinky.
mst Su-Shee: wrt the topic ["Su-Shee wants the web-development framework that makes web-development hard, difficult and complicated"], it's called Maypole :)
rindolf mst: heh.
rindolf mst: yes, I can imagine that about Maypole.
Su-Shee mst, avar: thank you so much. ;)
Su-Shee please mail the sourcecode to rindolf who put it in the topic ;)
rindolf Su-Shee: I can CPAN it.
Su-Shee the topic?
mutewit I have a string and am looking for a quick way to extract all 5-character slices out of it.
rindolf Su-Shee: :-)
rindolf IRC-Freenode-Perl-Topic-SuShee-WebDevelFrameworks-v0.0.1.tar.gz
mutewit For eg. 'abcdef' returns 'abcde', 'bcdef'
mutewit Any suggestions?
rindolf mutewit: use subst
rindolf mutewit: use substr
rindolf mutewit: with a map
rindolf eval: my $long_str = "0123456789abcdefgh"; [map { substr($long_s, $_, $_+5 } (0 .. length($long_s)-5)]
buubot rindolf: ERROR: syntax error at (eval 36) line 1, at EOF
rindolf eval: my $long_str = "0123456789abcdefgh"; [map { substr($long_s, $_, $_+5) } (0 .. length($long_s)-5)]
buubot rindolf: []
mutewit rindolf: Awesome.
rindolf eval: my $long_s = "0123456789abcdefgh"; [map { substr($long_s, $_, $_+5) } (0 .. length($long_s)-5)]
buubot rindolf: ["01234", 123456, 2345678, "3456789a", "456789abc", "56789abcde", "6789abcdefg", "789abcdefgh", "89abcdefgh", "9abcdefgh", "abcdefgh", "bcdefgh", "cdefgh", "defgh"]
rindolf Thrid time the charm!
mst ... thrid
* rindolf hits buubot with a big strict pragma.
* mst turns the slipper on rindolf
rindolf mst: yes, my typing sucks today.
rindolf But f**k it! IRC is not exactly the declaration of independence.
pragma_ ow!
rindolf pragma_: pardon?
* rindolf hits pragma_ with mst's slipper so it will really hurt.
pragma_ why are you hitting buubot with me?
rindolf pragma_: the strict pragma.
rindolf pragma_: not you.
rindolf perlbot: strict
perlbot rindolf: Perl strictures - http://perldoc.perl.org/strict.html
rindolf pragma_: ^^^
rindolf pragma_: we call the lowercase modules pragmata (sp?) in Perl.
rindolf http://en.wiktionary.org/wiki/Special:Search?search=pragmata - hmm....
rindolf I thought pragmata was a valid plural of pragma.
dngor ow? ow!
mutewit rindolf: Are you sure that generates only strings of length 5?
rindolf mutewit: well, you need to watch from fencepost errors.
mst mutewit: hey, he got you half way there
rindolf mutewit: oh wait.
mst mutewit: how about you read p3rl.org/substr and p3rl.org/map and have a go yourself
rindolf mutewit: yes , you need substr($long_s, $_, 5)
mst mutewit: this is a help-you-to-learn channel
mst mutewit: not a "write your code for you" channel
rindolf mutewit: and beware from fencepost errors.
rindolf like substr($long_s , 1000, 5)
rindolf Because that will be ""
rindolf Or a 4 chars length.
mutewit rindolf: I wanted the length argument to be 5 :p
mutewit mst: I understand, I just missed the $_ + 5 issue.
mst mutewit: right. what I'm saying is, you should have experimented
rindolf mutewit: yes, I know.
mst mutewit: 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"
mst mutewit: then we can help you learn
mst mutewit: assuming learning to write stuff yourself is what you're aiming for
* rindolf waits 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 ;)
rindolf mst: I think that's the case, no need to preach to mutewit about it.
mutewit mutewit: I did, and figured out the soln. when switching windows.
mst mutewit: aye. I'm just trying to explain how to get the most learning out of us as well as the most working code.
* rindolf sometimes thinks we spend much more IRC volume discussing netiquette than actually suffering from the bad netiquette.
mutewit But by the time I came back to the channel there was a whole page of "preaching".
mutewit I was using a split method with array indexing and it felt too much like a C-approach.
rindolf mutewit: oh, you split the string into chars?
mst yeah, by the time you've done map, join, split, ...
mst you've basically just reimplemented substr badly :)
mutewit rindolf: That's what I was doing, but the map/substr approach is a lot cleaner.
rindolf mutewit: yeah/
rindolf mutewit: split into chars sometimes has some uses.
rindolf mutewit: but this reminds me too much of SICP.
rindolf perlbot: sicp
perlbot rindolf: http://mitpress.mit.edu/sicp/ - "Structure and Interpretation of Computer Programs" - A Classical Text on Programming
rindolf mutewit: see - http://www.shlomifish.org/lecture/Perl/Lightning/Too-Many-Ways/slides/slide13.html
rindolf mutewit: this is how an SICP programmer will implement a simple text processing task.
mutewit SICP, love the book.
mutewit and all the OCaml work this year has given rise to a functional bent of mind
mutewit which is kinda screwing around with my perl code.
rindolf mutewit: yeah.
rindolf mutewit: http://www.shlomifish.org/lecture/Perl/Lightning/Too-Many-Ways/slides/slide12.html - this is the fastest Perl solution.
rindolf At least in speed.
rindolf It can be a little shorter with a regex lookahead, but it's less elegant and slower.
rindolf http://www.shlomifish.org/lecture/Perl/Lightning/Too-Many-Ways/slides/slide9.html - there you go.
rindolf mutewit: did you know how to program before reading SICP?
rindolf I think it's not a good introductory book.
rindolf MIT are going to ditch it in favour of some Python/Robotics curriculum.
mst I think it's only a good introductory book if you know some math and have the brain to follow it
mst it teaches a lot of hard concepts very quickly
Su-Shee mst: from a "I'm from the humanities department" point of view it's managable. it's not easy, but everyone can work with it.
tybalt89 eval: $_ = "0123456789abcdefgh"; [ /(?=(.{5}))/g ]
buubot tybalt89: ["01234",12345,23456,34567,45678,56789,"6789a","789ab","89abc","9abcd","abcde","bcdef","cdefg","defgh"]
mutewit rindolf: Yes.
rindolf mutewit: ah. Using what?
rindolf tybalt89++ # Up for the challenge.
mutewit and yes, MIT ditched SICP in favor of a Python-based intro course.
tybalt89 rindolf: I was off in other windows :(
tybalt89 mutewit: ^^ for 5 char slices
rindolf mutewit: don't use it if you want future generations to understand it.
* rindolf slaps tybalt89 with mst's slipper for golfing mutewit's solution and telling him it's a good idea.
tybalt89 rindolf: that's not golfing, just common simple regex :)
rindolf tybalt89: sigh.
rindolf tybalt89: simple.
rindolf irregular regular expression.
rindolf Maybe use Regexp::Common
mutewit I added in tybalt89's code but commented it for future reference.
mst I'd definitely use the substr approach for real code
mst tybalt89's code is cleverness to prove it can be done; I don't believe he was recommending it
tybalt89 mst: sigh, yes, I am recommending it. It's the clearest solution.
mst tybalt89: I respectfully disagree.
mst I find the substr approach far more obvious
Chazz rindolf, ty. :)
mst but then, I mostly write applications perl rather than scripts, so I only engage in regexp cleverness when actively useful
rindolf tybalt89: look-aheads and look-behinds are dark corners of the Perl not-so-reg-regexes
Yaakov In 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.
tybalt89 mst: note it took rindolf three tries, and even then he got it wrong.
rindolf tybalt89: well, I'm not focused now.
mst tybalt89: map substr($str, $_, 5), 0 .. length($str)-5; ?
mst maybe -6
* tybalt89 turns the lens, trying to focus rindolf
rindolf mst: -5
mst but it's hardly difficult; rindolf's just having a day of silly mistakes
rindolf Unit tests!
mst I'd expect him to get it right first time when on form too :)
rindolf Some clear code is hard to get right.
rindolf Doesn't make it less clear.
mst yeah
rindolf Most people will not write a correct binary search at first try.
tybalt89 "maybe -6" is proof of unclearness :)
rindolf But the correct binary search is easy to digest.
mst tybalt89: no, it's proof it's 8pm on a sunday and I'm not particularly awake either
mst but your code just made me go "hang on, WHAT?!"
mst then I had to stop and dissect it
mst -then- I saw what you were doing
rindolf mst++
mst also, the substr approach displays the semantics and the reasoning
mst whereas the regex approach displays, well, line noise, frankly
rindolf mst: why don't we agree to disagree with tybalt89 ?
rindolf mst: so how's the weather? ;-)
Channel #perl
Network Freenode
Tagline Slippers and Perl