in reply to Regular Exp parsing

or this..
$string = "Fri Nov 8 15:00:02 2002:"; my ($1, $2, $3, $4, $5) = split(/ /, $string);

Replies are listed 'Best First'.
Re: Re: Regular Exp parsing
by MarkM (Curate) on Dec 13, 2002 at 18:54 UTC
    You can't use $1, $2, ... in my(). It would be far better to avoid using $1, $2, ... altogether and use properly named variables that do not have any scoping issues.
Re: Re: Regular Exp parsing
by Cabrion (Friar) on Dec 14, 2002 at 14:13 UTC
    or this..

    $string = "Fri Nov 8 15:00:02 2002:"; my ($1, $2, $3, $4, $5) = split(/ +/, $string);

    Noting that the + allows for one or more spaces.

      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.

        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, ...'