Saving the whole array and then popping off the last element uses up lines and adds variables. I'd rather wrap the split in parentheses and reference the last element.
my $suffix = ( split /\./, $filename )[-1];
The only danger is that if the only reason you're getting the suffix is to print it, you need more parentheses to prevent print from thinking a subset of the expression is its argument list:
print ( split /\./, $filename )[-1]; # wrong
print (( split /\./, $filename )[-1]); # unpleasant
As Occam said: Entia non sunt multiplicanda praeter necessitatem.
|