in reply to Re: Re: Split an array -> store contents into a scalar up till a certain character
in thread Split an array -> store contents into a scalar up till a certain character

I'd advise against using four variables, and instead, would advocate using a single array. For example:
my $addr = "25.255.2.0"; my @scalar = split(/\./, $addr);
Then later, you can use it just as you would a regular scalar:
print "The address is $scalar[0].$scalar[1].$scalar[2].$scalar[3]\n";
There are many advantages to using an array instead of multiple scalars, a simple one being that this could also be expressed more simply as:
print "The address is ",join('.',@scalar),"\n";
There are few differences between $scalar[1] and $scalar_2 otherwise.

Replies are listed 'Best First'.
Re: Re^3: Split an array and store contents into a scalar up till a certain character
by FireBird34 (Pilgrim) on Oct 21, 2002 at 02:08 UTC
    Hmm... makes more sense. I'll try that method out. To add onto the rest of what I'm doing, this might make things alot easier.