in reply to Re: shorter 1 liner way of doing this
in thread shorter 1 liner way of doing this

hmm I was thinking more of a perl way, without including external libs. Like for example:
map($_=~/xxx/g ? push(@m,$i) : $i++) for(@array); print @m;
clearly not working :D

Replies are listed 'Best First'.
Re^3: shorter 1 liner way of doing this
by LanX (Saint) on Dec 27, 2015 at 22:15 UTC
    > clearly not working :D

    combining map and for gives two nested loops.

    maybe you meant this?

    DB<102> my $i=0; @m= map { $_=~/xxx/ ? $i++ : () } @a => (0, 1, 2)

    UPDATE
    DB<104> my $i=-1; @m= map { $i++; $_=~/xxx/ ? $i :() } @a => (1, 4, 6)

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

Re^3: shorter 1 liner way of doing this
by fishmonger (Chaplain) on Dec 27, 2015 at 21:47 UTC

    Why are you against using a module? It's just as "perlish" as the grep version and it's shorter and more self documenting.