joggi has asked for the wisdom of the Perl Monks concerning the following question:

$value=/home/image/office.iso how can I get "office" or "office.iso"?

Replies are listed 'Best First'.
Re: How can I get the file name
by snowcrash (Friar) on May 14, 2003 at 09:38 UTC
    File::Basename does the job:
    use File::Basename; my ($name,$path,$suffix) = fileparse('/home/image/office.iso','\..*');
    cheers
    snowcrash
Re: How can I get the file name
by teabag (Pilgrim) on May 14, 2003 at 09:41 UTC
    or, quick and dirty,
    $filename = (split("/", $value))[-1];

    Teabag
    Sure there's more than one way, but one just needs one anyway - Teabag

Re: How can I get the file name
by broquaint (Abbot) on May 14, 2003 at 09:42 UTC
    A simple regex will do it
    my $value = "/home/image/office.iso"; my($fullname, $filename) = $value =~ m< / ( ( [^/]+ ) \. .* ) \z >x; print "fullname - $fullname\nfilename - $filename\n"; __output__ fullname - office.iso filename - office
    Or if you're expecting to port the code, File::Spec is the way to go
    use File::Spec::Functions 'splitpath'; my $value = "/home/image/office.iso"; my($fullname,$filename) = (splitpath $value)[-1] =~ m< ( ([^\.]+) \. .*) >x; print "fullname - $fullname\nfilename - $filename\n"; __output__ fullname - office.iso filename - office
    See. perlre and File::Spec::Functions for more info.
    HTH

    _________
    broquaint

Re: How can I get the file name
by rupesh (Hermit) on May 14, 2003 at 12:49 UTC
    Try this:
    print substr(substr($value, rindex($value, '/')),1), "\n";

    we're born with our eyes closed and our mouths wide open, and we spend our entire life trying to rectify that mistake of nature. - anonymous.