- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Perl script problem - file::find
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-07-2005 11:26 PM
тАО03-07-2005 11:26 PM
Was hoping one of you would be able to point me in the right direction, I know this probably isn't the right place to be posting it....
Am writing a perl admin script, which needs to find a bunch of files passed as parameters to the script:
My script basically looks like this:
use strict;
use File::Find;
my $dir = "$ARGV[0]" ;
shift @ARGV;
foreach (@ARGV) {
find(\&wanted, '$dir', '$_');
}
sub wanted { /$ARGV[1]/ && print "$File::Find::name\n;" }
It doesn't work. Have tried various other methods... Can anyone give me a quick pointer how to go about this?
TIA
Nick
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-08-2005 01:16 AM
тАО03-08-2005 01:16 AM
Solutionuse strict;
use File::Find;
sub usage
{
print STDERR "usage: $0 dir file ...\n";
exit;
} # usage
my $dir = shift;
-d $dir or usage;
@ARGV or usage;
my $files = join "|" => @ARGV;
$files = qr{$files};
find (sub { m/$files/ and print "$File::Find::name\n" }, $dir);
-->8---
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-08-2005 02:07 AM
тАО03-08-2005 02:07 AM
Re: Perl script problem - file::find
(Sorry, am a Perl newbie. What's
Thanks again
Nick
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-08-2005 02:32 AM
тАО03-08-2005 02:32 AM
Re: Perl script problem - file::find
Your major `fault' however was the argument passing in
foreach (@ARGV) {
find (\&wanted, '$dir', '$_');
}
where $dir should NOT be single quoted, because then you are trying to parse the folder that is called $dir literally (and I bet you that that folder/dir does not exist), instead of deparsing the folder that is named by the *content* of the $dir variable
second problem you created is to pass '$_', which again should not have been quoted for now obvious reasons, but find takes the following arguments:
find (sub, dir, ...)
so the first arg is a sub reference, which can be a reference to a named sub, a variable that holds the reference to a named sub or closure, or a closure, which was what I used in my example.
the second and consequetive arguments are dirs or folders, and you tried to pass a filename (tried, because you single quoted it, causing the *literal* $_ to be passed) as third argument, something find cannot descend into
for qr, do
# man perlop
search for
Regexp Quote-Like Operators
to read
--8<---
qr/STRING/imosx
This operator quotes (and possibly compiles) its STRING as a
regular expression. STRING is interpolated the same way as
PATTERN in "m/PATTERN/". If "'" is used as the delimiter, no
interpolation is done. Returns a Perl value which may be used
instead of the corresponding "/STRING/imosx" expression.
For example,
$rex = qr/my.STRING/is;
s/$rex/foo/;
is equivalent to
s/my.STRING/foo/is;
-->8---
Hope this helps.
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-09-2005 09:50 PM
тАО03-09-2005 09:50 PM