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

Uri London uril at exchange.microsoft.com
Tue Jun 28 15:00:38 PDT 2005


 

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

More interestingly, why #2 doesn't work, while #3 does?

 

 

For example:

 

$path = `cd`;

 

# 1. working, but I've been told not very efficient:

$base = (split /\\/, $path)[-1];

 

 

# 2. this isn't working for me. Why???

$base = pop split /\\/, $path;

 

 

# 3. This is similar to above, but does work.

@tmp = split /\\/, $path;

$base = pop @tmp;

 

# 4. Work, but I believe slower:

($base) = $path =~ /.*\\([^\\])/;

 

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/spug-list/attachments/20050628/e4823175/attachment.html


More information about the spug-list mailing list