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

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.

Replies are listed 'Best First'.
Re: Re: Re: Regular Exp parsing
by Cabrion (Friar) on Dec 14, 2002 at 14:16 UTC
    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, ...'