--- Connie Chan <[EMAIL PROTECTED]> wrote:
> say,  $a = "1234:4321;abcde;fghij::;klmno";
> In case, I want $x = "1234" , $y = "4321", $data = "abcde;fghij::;klmno"
> Then I do in this way :
> 
> @dataLine = split(/;/, $a);
> ($x, $y) = split (/:/, $dataLine[0]);
> $data = join(";", shift(@dataLine));
> 
> So I can get the result what I want... but, anybody can suggest me if
> this process can be done simplier ?

    use strict;
    my $stuff = "1234:4321;abcde;fghij::;klmno";
    my ( $x, $y, $data ) = split /[;:]/, $stuff, 3;
    print "$x\n$y\n$data";

Be careful using this, though.  It's easy to get the regex wrong.  Also, note the 
optional third
argument to split which restricts the split to 3 elements.  And I wouldn't use $a as a 
variable
name.  That can cause problems when you use the "magical" $a and $b variables in sorts 
(e.g. sort
$a <=> $b).

Hope that helps.

Cheers,
Curtis "Ovid" Poe

=====
"Ovid" on http://www.perlmonks.org/
Someone asked me how to count to 10 in Perl:
push@A,$_ for reverse q.e...q.n.;for(@A){$_=unpack(q|c|,$_);@a=split//;
shift@a;shift@a if $a[$[]eq$[;$_=join q||,@a};print $_,$/for reverse @A

__________________________________________________
Do You Yahoo!?
Send your FREE holiday greetings online!
http://greetings.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to