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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.