in reply to Finding a extention

I use File::Basename It hasn't failed me yet.
use File::Basename; my @exts = qw(.html .htm .shtml .pl .cgi .txt .etc); # list which ever + extensions you will be using. my $file1 = "people.htm"; # the file you want to parse ($name,$path,$suffix) = fileparse($file1,@exts); print "$suffix";
returns: '.htm'

-Silent11

Replies are listed 'Best First'.
Re: Re: Finding a extention
by Rich36 (Chaplain) on Oct 05, 2002 at 16:32 UTC

    You can also use a regex so that you don't have to worry about listing all the possible extensions.

    foreach("fp.html", "fp.cgi", "fp.pl", "fp.foo", "fp.blah") { my ($base, $path, $type) = fileparse("/home/users/rich36/$_", qr{\ +..+}); print qq($base, $path, $type\n); } __RESULT__ fp, /home/users/rich36/, .html fp, /home/users/rich36/, .cgi fp, /home/users/rich36/, .pl fp, /home/users/rich36/, .foo fp, /home/users/rich36/, .blah
    «Rich36»