in reply to Re: how to Check file type?
in thread how to Check file type?
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: how to Check file type?
by ChuckularOne (Prior) on Dec 02, 2010 at 20:24 UTC |