in reply to Simplify This

Of the two solutions presented by jonadab, which is the preferred way?
@iparray = $record =~ /^\s*(\d+)[ .]+(\d+)[ .]+(\d+)[ .](\d+)/;
alternately,
@iparray = map {s/ //g;$_} split /[.]/, substr ($record,0,17);

Replies are listed 'Best First'.
Re: Re: Simplify This
by dragonchild (Archbishop) on Sep 30, 2003 at 19:51 UTC
    The first is better because it's stricter. You definitely want to get the strictest parsing you can, for safety.

    ------
    We are the carpenters and bricklayers of the Information Age.

    The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

Re: Re: Simplify This
by Not_a_Number (Prior) on Sep 30, 2003 at 19:58 UTC

    I agree with dragonchild. I wouldn't use substr like that:

    my $record = " 127.0.0.1 1COMPUTER1 09/13/30828 22:48:05"; my @iparray = map {s/ //g;$_} split /[.]/, substr ($record,0,17); print "@iparray";

    Output:

    127 00 11COM

    dave