Ravi Malghan wrote:
> Hi: I want to split the string
> 0.0.0.0.1.10.1.30.1.10.1.30.1
> 
> into 4 variables: 0.0.0.0, 1, 10.1.30.1 and 10.1.30.1
> 
> any suggestions?
> 
> TIA
> ravi
Here is one approach:

#!perl -w

use strict

$_ = '0.0.0.0.1.10.1.30.1.10.1.30.1';

my @MyWorka = ();
@MyWorka = split(/\./, $_);
my @MyWorkb = ();
my @MyWorkc = ();
my @MyWorkd = ();

@MyWorkb = splice(@MyWorka,-4,4);
@MyWorkc = splice(@MyWorka,-4,4);
@MyWorkd = splice(@MyWorka,-1,1);

printf "%-s, %-s, %-s, %-s\n",
                                join('.', @MyWorka),
                                @MyWorkd,
                                join('.', @MyWorkc),
                                join('.', @MyWorkb);

Output:
0.0.0.0, 1, 10.1.30.1, 10.1.30.1

Wags ;)
> 
> __________________________________
> Do you Yahoo!?
> New Yahoo! Photos - easier uploading and sharing.
> http://photos.yahoo.com/



**********************************************************
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
****************************************************************


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to