SPUG: spug: What is the idiomatic way to extract first/last item after split?

Bill Campbell bill at celestial.com
Tue Jun 28 15:14:39 PDT 2005


On Tue, Jun 28, 2005, Uri London wrote:
>
>
>   What is the idiomatic way to extract first/last item after split?
>
>   More interestingly, why #2 doesn't work, while #3 does?

If I want the first and last items from a split, I would probably do it
something like:

	my ($first, @rest) = split(...);
	my $last = pop(@rest);

If working with file names, I'm more likely to use File::Basename and/or
the tools in File::Path to do something that's not OS dependent.

Bill
--
INTERNET:   bill at Celestial.COM  Bill Campbell; Celestial Software LLC
UUCP:               camco!bill  PO Box 820; 6641 E. Mercer Way
FAX:            (206) 232-9186  Mercer Island, WA 98040-0820; (206) 236-1676
URL: http://www.celestial.com/

``I have learned what some people are like.  And if some people are like
that, other people must have the means to shoot them.''
	Donald Hamilton -- The Vanishers


More information about the spug-list mailing list