----- Original Message ----- From: ""Saurabh Singhvi"" <[EMAIL PROTECTED]>
Newsgroups: perl.beginners To: "Perl FAq" <beginners@perl.org> Sent: Thursday, May 25, 2006 3:38 PM Subject: split doubt
Hi the format of split() defines that one can split a string into a fixed number of specifies strings. for eg ($login, $passwd, $remainder) = split(/:/, $_, 3); Now, the thing is, it splits on first 3 parts. Can i do the reverse?? as in instead of the output being the first 3 parts of split, the last 3 parts of split for the same string. thanks Saurabh
Sure, the code below will do that. Chris #!/usr/bin/perl use strict; use warnings; my $string = "a;b;c;d;e;f"; my ($stuff1, $stuff2, $stuff3) = (split /;/, $string)[-3..-1]; print "$stuff1 $stuff2 $stuff3\n"; __END__ this prints... d e f -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>