[ILUG] [OT] perl help
Fergal Daly
fergal at esatclear.ie
Fri Sep 15 11:20:56 IST 2000
\1, \2 etc. only work on the left hand side of a regex, you probably meant
to use $1, $2 etc. which stick around until the next regex is executed.
Or you could do
if (($v1, $v2, $v3) = /^([A-Za-z]{3}) ([0-9]{2}) ([0-9{2}).*$regex[$i]/) {
because when executed in a list context, a regex will return a list of the
bracketed strings rather the number of them. So you can do
@bits = /complicated regex/;
if you have way to many or an uknown number of brackets in there
and
@bits = ($string =~ /complicated regex/);
if you want to match against something besides what's in $_
Fergal
On Wed, Sep 13, 2000 at 04:33:15PM +0100, Paul Jakma wrote:
> as per kevin l.'s suggestion i've decided to try my hand at perl
> (and cause this list could do with a spate of perl newbie questions)..
>
> so i'm trying to capture parts of the results of a /regex/ into
> variables, eg something along the lines of:
>
> basically i'm trying to figure out how to do something like the
> following:
>
> while (<MSGS> ) {
> if (/^([A-Za-z]{3}) ([0-9]{2}) ([0-9{2}).*$regex[$i]/) {
> $month[$i] = \1;
> $date[$i] = \2;
> $hour[$i] = \3
> }
>
> how do it? how can i catch what \1, \2 and \3 match and store them in
> variables?
>
> thanks,
>
> --paulj
>
>
> --
> Irish Linux Users' Group: ilug at linux.ie
> http://www.linux.ie/mailman/listinfo/ilug for (un)subscription information.
> List maintainer: listmaster at linux.ie
More information about the ILUG
mailing list