in reply to Using Basename

Just use map with File::Basename and make sure you drop the trailing newlines
use File::Basename; my @basenames = map basename($_), my @result = map { chomp; $_ } `find '.' -type f -print -name '*.pl'` or die "No scripts found - $! \n";
Or more perl-ishly
use File::Basename; use File::Find::Rule; my @basenames = map basename($_), my @result = find(file => name => "*.pl", in => ".") or die "No scripts found - $! \n";
See. map, File::Basename and File::Find::Rule for more info.
HTH

_________
broquaint

Replies are listed 'Best First'.
Re: Re: Using Basename
by blueapache (Acolyte) on Nov 17, 2003 at 17:08 UTC
    thanks for that. I tried first option but having problems picking up correct files and printing. doesn't seem to recognise *.pl and I'm wondering whether using the current directory is causing a problem. First return off print statement looked like the opening screen of the matrix
      blueapache,
      broquaint said HTH (had to hurry). Try this slightly modified code:
      #!/usr/bin/perl -w use strict; use File::Basename; my @result = `find '.' -type f -name '*.pl' -print` or die "No scripts + found - $! \n"; chomp @result; my @basenames = map { basename($_) } @result; print $_, $/ for @basenames;
      Cheers - L~R
        broquaint said HTH (had to hurry).

        How about "Hope This Helps" or "Hope That Helps" or "Happy To Help" maybe?

        I'd guess broquaint meant one of the first two as the last is usually offered after a "thanks".

        -sauoq
        "My two cents aren't worth a dime.";
        
        Limbic~Region:

        I read HTH, especially at the end of a message, as Hope That Helps.

        edit: oops, missed sauoq's more timely reply

        thanks this works a treat