On Tue, Apr 14, 2009 at 10:02, Michael Alipio <daem0n...@yahoo.com> wrote: > > >> >> Or use split and return the last field: >> >> $ perl -le' >> my $string = "boy, pig, 123, 123:412adbd, d0g, >> lajdlf134><<_ lkadsf !234,\n"; >> my $value = ( split /,\s+/, $string )[ -1 ]; > > Another mind bogling example... :-) > I thought I would do: > > my @value = ( split /,\s+/, $string ); > print $value[6]; snip
That only works if you are certain you want the seventh item. If you always want the last item (regardless of how many items are in the array) you should say either print $value[$#value]; or print $value[-1]; Since you don't care about the other values it is probably better to index into the list than to store to a temporary array. -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/