Code Comments
Programming Forum and web based access to our favorite programming groups.How does one extract check for the file extension part or a filename in Perl? Thanks
Post Follow-up to this messageDeke <Deke@nospam.com> 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/per...ile/Basename.pm
Sinan.
Post Follow-up to this messageDeke wrote: > How does one extract check for the file extension part or a filename > in Perl? Any particular problems with File::Basename? jue
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.