On Thu, 2006-25-05 at 13:17 -0700, Joshua Colson wrote: > On Thu, 2006-05-25 at 19:38 +0000, Saurabh Singhvi wrote: > > 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. > > I'm sure there is a cleaner way to write this, but try: > > ($gecos, $home, $shell) = ( split(/:/, $_) )[-3..-1]; > >
Wrong! There is no way split can do the reverse of splitting of the first 2 parts of a string and placing the rest in the third part. Something that may come close is: my @data = split /:/, $_; my $last = pop @data; my $next_to_last = pop @data; my $remainder = join( ':', @data ); -- __END__ Just my 0.00000002 million dollars worth, --- Shawn "For the things we have to learn before we can do them, we learn by doing them." Aristotle * Perl tutorials at http://perlmonks.org/?node=Tutorials * A searchable perldoc is at http://perldoc.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>