in reply to Extracting just the extension from a filename.

Try something like this:
my $fileName = "20020719.csv"; $fileName =~ /\.(\w+)$/; my $extension = $1;

Jason

Replies are listed 'Best First'.
Re: Re: Extracting just the extension from a filename.
by moxliukas (Curate) on Jul 19, 2002 at 19:25 UTC

    This would work OK, but if the extension would contain some `funny' characters you could get into problem. It is not very often that you get extensions with spaces and other weird things, but hey, you never know. So my solution would be:

    my $filename = '20020719.csv'; $filename =~ /\.([^\.]*)$/; my $extension = $1;
Re: Re: Extracting just the extension from a filename.
by simeon2000 (Monk) on Jul 19, 2002 at 20:18 UTC
    Good solution. My only additions would be to use \^\.\ instead of \w to catch \W as well but not ".".

    You could also one-line it by catching the matches with alist assignment to avoid reading from $1:

    my ($extension) = $filename =~ /\.([^\.]+)$/;