while loop -> map

2005-05-24 Thread Robert Citek
I found a variation of this in the Perl Nutshell book: $ perl -le ' $foo="fee fie foe foo" ; while ($foo =~ m/e/g ) { push @bar, pos $foo ; } print join(":", @bar); ' 2:3:7:11 Is there an equivalent way to do the same using map instead of an explicit while loop? I'm guessing not, sinc

Re: while loop -> map

2005-05-24 Thread Xavier Noria
On May 24, 2005, at 19:22, Robert Citek wrote: I found a variation of this in the Perl Nutshell book: $ perl -le ' $foo="fee fie foe foo" ; while ($foo =~ m/e/g ) { push @bar, pos $foo ; } print join(":", @bar); ' 2:3:7:11 Is there an equivalent way to do the same using map instead of a

Re: while loop -> map

2005-05-24 Thread John Doe
Am Dienstag, 24. Mai 2005 19.22 schrieb Robert Citek: > I found a variation of this in the Perl Nutshell book: > > $ perl -le ' > $foo="fee fie foe foo" ; > while ($foo =~ m/e/g ) { > push @bar, pos $foo ; > } > print join(":", @bar); ' > 2:3:7:11 > > Is there an equivalent way to do th

Re: while loop -> map

2005-05-24 Thread Ing. Branislav Gerzo
Xavier Noria [XN], on Tuesday, May 24, 2005 at 22:12 (+0200) typed the following: XN> my $i = 0; XN> my @bar = map $_->[1], # take second component XN>grep $_->[0] eq 'e', # let 'e's pass XN>map [$_, ++$i],# arrayref [char, index of cha

Re: while loop -> map

2005-05-24 Thread Offer Kaye
On 5/24/05, Robert Citek wrote: > > I found a variation of this in the Perl Nutshell book: > > $ perl -le ' > $foo="fee fie foe foo" ; > while ($foo =~ m/e/g ) { > push @bar, pos $foo ; > } > print join(":", @bar); ' > 2:3:7:11 > > Is there an equivalent way to do the same using map

Re: while loop -> map

2005-05-25 Thread Jay Savage
On 5/24/05, Robert Citek <[EMAIL PROTECTED]> wrote: > > On May 24, 2005, at 3:14 PM, Jay Savage wrote: > > One thing that springs to mind is: > > > >perl -le ' > >$foo = "fee fie foe foo"; > >map {$i++; push @bar, $i if $_ eq "e"} split //, $foo; > >print join(":",@bar)' > > > > I'

Re: while loop -> map

2005-05-25 Thread Jay Savage
On 5/25/05, Jay Savage <[EMAIL PROTECTED]> wrote: > On 5/24/05, Robert Citek <[EMAIL PROTECTED]> wrote: > > I like your idea. Unfortunately, the above works only in the special > > case where the regular expression match is actually a single- > > character, exact match. > > > > Regards, > > - Robe

Re: while loop -> map

2005-05-25 Thread Jeff 'japhy' Pinyan
On May 25, Jay Savage said: /e(?{push @bar, pos})/g; should work, but seems to ignore the /g. Because as you wrote it, the regex is in void context, which means it'll only match once. Put it in list context: () = /e(?{ push @bar, pos })/g; But this looks weird to almost anyone. I'd d

Re: while loop -> map

2005-05-25 Thread Jay Savage
On 5/25/05, Jeff 'japhy' Pinyan <[EMAIL PROTECTED]> wrote: > On May 25, Jay Savage said: > > > /e(?{push @bar, pos})/g; > > > > should work, but seems to ignore the /g. > > Because as you wrote it, the regex is in void context, which means it'll > only match once. Put it in list context: > >

Re: while loop -> map

2005-05-25 Thread Jay Savage
On 5/25/05, Jay Savage <[EMAIL PROTECTED]> wrote: [snip] >/p(?:{push @bar, pos})attern(?!)/g oops! make that: /p(?{push @bar, pos})attern(?!)/g -- daggerquill [at] gmail [dot] com http://www.engatiki.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional c

Re: while loop -> map

2005-05-25 Thread Jeff 'japhy' Pinyan
On May 25, Jay Savage said: On 5/25/05, Jeff 'japhy' Pinyan <[EMAIL PROTECTED]> wrote: On May 25, Jay Savage said: /e(?{push @bar, pos})/g; should work, but seems to ignore the /g. Because as you wrote it, the regex is in void context, which means it'll only match once. Put it in list co