anjaana78 has asked for the wisdom of the Perl Monks concerning the following question:

Hi, How do i find the word followed by a specific word. For example:
$str = "select canned food from store where food1=tuna, food2= catfish +"
now i have to select the word after food1=
so the answer should be tuna. thanks a lot.
-bari

Replies are listed 'Best First'.
Re: how do i find the word following a specific word
by Arguile (Hermit) on Jun 18, 2001 at 18:36 UTC
    $str =~ /food1=(\w+)/; print $1;

    The parenthesis 'remeber' what's inside of them, so the $1 variable contains the first remebered variable (from left to right): If you had more parenthesis, they would go into $2, $3, .. $9. You can find more about regular expressions here.

    As a side note, you might want to check out DBI if you're dealing with databases.