On Mon, Mar 10, 2008 at 1:37 AM, igotux igotux <[EMAIL PROTECTED]> wrote: > Hi, > I want to extract values from split without defining an array. Say i want to > access second element in the split output :- split (/\s+/,$var) . I tried > split(/\s+/,$var)[1] which is not working as i expected. Can someone please > correct me on this ? > > Thanks, > IGotux >
One method is using undef For example if you we're only interested in fields 1,3, and 5 you could do something like ($field1,undef,$field3,undef,$field5) = split/.../; Or you can do something like (split//...)[3] #!/usr/bin/perl -w use strict; use warnings; my $s = "This,is,a,test"; my ($capture) = (split/,/,$s)[3]; print $capture,"\n"; -- Rodrick R. Brown http://www.rodrickbrown.com http://www.linkedin.com/in/rodrickbrown -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/