File extension extraction from filename
am 12.10.2004 23:37:36 von DekeHow does one extract check for the file extension part or a filename in
Perl?
Thanks
How does one extract check for the file extension part or a filename in
Perl?
Thanks
Deke
> How does one extract check for the file extension part or a filename in
> Perl?
I assume the filenames you are interested in are in the following format:
name.extension
That is, I am going to require that the extension of
..bashrc
is blank.
We are interested in the string following the last period in the name:
#! /usr/bin/perl
use strict;
use warnings;
my @list = qw(name name.extension .extension);
for (@list) {
my ($ext) = /.+\.(\w+)?$/;
defined $ext or $ext = '';
print "Name: $_\tExtension: $ext\n";
}
__END__
Also, look into File::Basename::fileparse
http://search.cpan.org/~nwclark/perl-5.8.5/lib/File/Basename .pm
Sinan.
Deke
> How does one extract check for the file extension part or a filename in
> Perl?
I assume the filenames you are interested in are in the following format:
name.extension
That is, I am going to require that the extension of
..bashrc
is blank.
We are interested in the string following the last period in the name:
#! /usr/bin/perl
use strict;
use warnings;
my @list = qw(name name.extension .extension);
for (@list) {
my ($ext) = /.+\.(\w+)?$/;
defined $ext or $ext = '';
print "Name: $_\tExtension: $ext\n";
}
__END__
Also, look into File::Basename::fileparse
http://search.cpan.org/~nwclark/perl-5.8.5/lib/File/Basename .pm
Sinan.
Deke wrote:
> How does one extract check for the file extension part or a filename
> in Perl?
Any particular problems with File::Basename?
jue
Deke wrote:
> How does one extract check for the file extension part or a filename
> in Perl?
Any particular problems with File::Basename?
jue