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.
| [reply] [d/l] [select] |
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
| [reply] |
#!/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 | [reply] [d/l] |
The clauses of a find are carried out in order, left to right. If a clause succeeds, processing continues; if it fails, this candidate is abandoned and the next file tested.
- In the case above, -type f tests whether the current candidate is a file, or directory or link or something else. Processing continues only if it is a file.
- Next, the name of the file is printed. Printing always considered to succeed.
- Finally, the name is tested to see if matches the glb pattern, '*.pl'. Whether it matches or not, processing is finished for this candidate.
Presumably, what you really want is to defer printing until after you have selected only '*.pl' files:
.... `find '.' -type f -name '*.pl' -print` ....
info find or man find is your friend. In particular, watch for the case where you want to match one of two patterns, using -o. You have to group the patterns using parentheses, escaped to prevent the shell from interpreting them:
find . \( -name '.pl' -o -name '*.pod' \) -print
--
TTTATCGGTCGTTATATAGATGTTTGCA
| [reply] [d/l] [select] |
you must have read my mind, used broquaint's code which works great but I was trying to do what your code does, just one step at a time
| [reply] |