in reply to 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

Ok, thanks all. I have it now.

my ( $scalar_1, $scalar_2, $scalar_3, $scalar_4 ) = split /\./, '25.255.2.0';

That did what I needed.
  • Comment on Re: Re: Split an array -> store contents into a scalar up till a certain character
  • Download Code

Replies are listed 'Best First'.
Re^3: Split an array and store contents into a scalar up till a certain character
by tadman (Prior) on Oct 19, 2002 at 23:47 UTC
    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.
      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.