in reply to Re: Re: Regular Exp parsing
in thread Regular Exp parsing

Oops, corrected as the use of $1, $2, etc. wouldn't work as pointed out above since they are "magic" variables used by regexps.

$string = "Fri Nov 8 15:00:02 2002:"; my ($a, $b, $c, $d, $e) = split(/ +/, $string);

Noting that the + allows for one or more spaces.

Replies are listed 'Best First'.
Re: Re: Re: Re: Regular Exp parsing
by hardburn (Abbot) on Dec 16, 2002 at 15:24 UTC

    I'd prefer it to match any whitespace, not just SP:

    $string = "Fri Nov 8 15:00:02 2002:"; my ($a, $b, $c, $d, $e) = split(/\s+/, $string, 5);

    Notice that I also limit the number of results to 5.

    As said in another node, you probably want to chop() off the colon, too (or use substr() instead). Also, you want to use variable names that are more descriptive than '$a, $b, $c, ...'