File extension extraction from filename

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

Thanks
Deke [ Di, 12 Oktober 2004 23:37 ] [ ID #221783 ]

Re: File extension extraction from filename

Deke <Deke [at] nospam.com> wrote in news:10mojl1hbb74va0 [at] 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 [at] list = qw(name name.extension .extension);

for ( [at] 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.
usa1 [ Mi, 13 Oktober 2004 00:13 ] [ ID #221784 ]

Re: File extension extraction from filename

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

Any particular problems with File::Basename?

jue
jurgenex [ Mi, 13 Oktober 2004 03:24 ] [ ID #221785 ]

Re: File extension extraction from filename

Deke <Deke [at] nospam.com> wrote in news:10mojl1hbb74va0 [at] 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 [at] list = qw(name name.extension .extension);

for ( [at] 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.
usa1 [ Mi, 13 Oktober 2004 00:13 ] [ ID #221834 ]

Re: File extension extraction from filename

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

Any particular problems with File::Basename?

jue
jurgenex [ Mi, 13 Oktober 2004 03:24 ] [ ID #221844 ]
Perl » alt.perl » File extension extraction from filename

Vorheriges Thema: Fetching to and from and subject from MIME:Parser
Nächstes Thema: combination with wget and incresing number ?