in reply to Re: grep question
in thread grep question

Of course, if one is hellbent on using grep for this, Perl will oblige with WTDIs galore...

One such solution:

perl -e 'print grep { s/param=// } @{[ "param=value" ]};'

...but this hardly qualifies as an argument in favor of using grep here

Agreed. Other than as a proof-of-concept, don't do this. I'd personally use map for the OPs exact stated desire. I suspect, though, if the OP gave the larger context of the problem, better solutions might be apparent.

Replies are listed 'Best First'.
Re^3: grep question
by Tanktalus (Canon) on May 26, 2005 at 23:26 UTC

    Personally, I'd use both map and grep for what the OP is doing:

    return map { /memtype=(.*)/i; $1 } grep /memtype=/, $self -> collect_d +ata ('all');
    I realise that this probably doesn't speed things up, maybe even slows it down. But it does what it says much more obviously to me. I'm collecting all the data. Then I'm extracting just the ones I want (memtype), and then I'm grabbing the stuff on the right of the equals sign. Just seems more straightforward to me. As for brian d foy's concern about using $1 when you haven't checked if it matched, I hope this is ok - I agree with him, and I think this is ok. ;-)