in reply to Simplify This

I stuck with your overall approach using split and substr. I realize that the regex approaches already given are more elegant, but I am post-happy today. That s// operator returns the number of substitutions, which is what was foiling you. Comma can help, if you like.

$record = " 100.100.100.100 1COMPUTER1 09/13/30828 22:48:05"; @iparray = split(/\./, do{($copy = substr($record,0,17)) =~ s/ //, $co +py}); $" = "."; print "@iparray";

,welchavw

Replies are listed 'Best First'.
Re: Re: Simplify This
by ChrisR (Hermit) on Oct 01, 2003 at 00:33 UTC
    I agree that the regex's are the better choice here. I actually found the first one by BrowserUk to the best choice.
    @iparray = ( $record =~ m[(\d+)]g )[0..3];
    This is short and easy to understand.
    My mistake in returning the value was in the statement I was using for debugging.
    print "|" . join ".", @iparray . "|\n";
    My guess is that it was returning the number of elements joined. I fixed it as:
    print "|" . (join ".", @iparray) . "|\n";
    Thanks trying to help with a possible reason/answer to my mistake. After tending to the scrapes and bruises from this post, I am back on track and a little wiser for it.

    Thanks to all for your input!