Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

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

by dug (Chaplain)
on Oct 19, 2002 at 23:33 UTC ( [id://206582]=note: print w/replies, xml ) Need Help??


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

This should do it.
my($quad_1, $quad_2, $quad_3, $quad_4) = split /\./, $array[0];

Of course, I'm assuming that what you mean by having the address 25.255.2.0 in @array, is that the first element of @array is the string '25.255.2.0'. That would be the case if you did something like @array = '25.255.2.0' in order to get the address into your array.

If the address is in $string, simply replace $array[0] (the first element of @array) with $string and you should be good to go.

If what you mean is that the address was split into four elements and assigned to @array, something like @array = split /\./, '25.255.2.0';, then you can either just use the array indices directly, or assign them into temporary variables, like so:
$array[0] == '25' and print "The first quadrant is 25\n"; $quad_1 = $array[0]; $quad_2 = $array[1]; $quad_3 = $array[2]; $quad_4 = $array[3]; $quad_1 == '25' and print "The first quadrant is still 25\n";

  dug

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://206582]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-24 08:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found