File extension extraction from filename

File extension extraction from filename

am 12.10.2004 23:37:36 von Deke

How does one extract check for the file extension part or a filename in
Perl?

Thanks

Re: File extension extraction from filename

am 13.10.2004 00:13:00 von usa1

Deke wrote in news:10mojl1hbb74va0@news.supernews.com:

> 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.

Re: File extension extraction from filename

am 13.10.2004 00:13:00 von usa1

Deke wrote in news:10mojl1hbb74va0@news.supernews.com:

> 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.

Re: File extension extraction from filename

am 13.10.2004 03:24:00 von jurgenex

Deke wrote:
> How does one extract check for the file extension part or a filename
> in Perl?

Any particular problems with File::Basename?

jue

Re: File extension extraction from filename

am 13.10.2004 03:24:00 von jurgenex

Deke wrote:
> How does one extract check for the file extension part or a filename
> in Perl?

Any particular problems with File::Basename?

jue