in reply to grep question

One possible solution:
perl -le 'print map {/param=(.*)/;$1} "param=value";'
I just hope you're not planning on using this to process CGI arguments...

Replies are listed 'Best First'.
Re^2: grep question
by demerphq (Chancellor) on May 26, 2005 at 21:31 UTC

    I think you meant:

    perl -le 'print map { /param=(.*)/ ? $1 : () } "param=value";'

    $1 is only set if the match is succesful.

    (merlyn i beat you to it ;-)

    ---
    $world=~s/war/peace/g

      No, the OP describes the input as a 'param=value' list. I stand by my post.

        So, you would rather beleive that the input is always exacctly what you expect rather than add ten characters to handle the situations where it isn't? "Expected user input" tends to not be.

        In general, don't use any of the match variables without knowing the match succeeded. It doesn't matter what else is going on. Don't let yourself get into bad habits, or take shortcuts because you think the data will always be perfect.

        The real answer, however, smells like use CGI;

        --
        brian d foy <brian@stonehenge.com>
Re^2: grep question
by newest_newbie (Acolyte) on May 26, 2005 at 22:26 UTC
    Thanks

    Thanks for all the advises

    I actually had tried something like  map { /param=(.*)/; return $1; } which did not work.

    I have modified my code to be like this  return map { /memtype=(.*?)"/i ? $1 : (); } $self -> collect_data ('all'); as suggested by you monks!

    PS: I hope at least the reply post looks better !!