<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Perl script problem - file::find in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/perl-script-problem-file-find/m-p/4890093#M69858</link>
    <description>Hi,&lt;BR /&gt;&lt;BR /&gt;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....&lt;BR /&gt;&lt;BR /&gt;Am writing a perl admin script, which needs to find a bunch of files passed as parameters to the script:&lt;BR /&gt;&lt;BR /&gt;&lt;FIND_SCRIPT.PL directory="" file1="" file2="" file3=""&gt;&lt;BR /&gt;&lt;BR /&gt;My script basically looks like this:&lt;BR /&gt;&lt;BR /&gt;use strict;&lt;BR /&gt;use File::Find;&lt;BR /&gt;my $dir = "$ARGV[0]" ;&lt;BR /&gt;shift @ARGV;&lt;BR /&gt;foreach (@ARGV) {&lt;BR /&gt;   find(\&amp;amp;wanted, '$dir', '$_');&lt;BR /&gt;}&lt;BR /&gt;sub wanted { /$ARGV[1]/ &amp;amp;&amp;amp; print "$File::Find::name\n;" }&lt;BR /&gt;&lt;BR /&gt;It doesn't work. Have tried various other methods... Can anyone give me a quick pointer how to go about this?&lt;BR /&gt;&lt;BR /&gt;TIA&lt;BR /&gt;Nick&lt;/FIND_SCRIPT.PL&gt;</description>
    <pubDate>Tue, 08 Mar 2005 07:26:41 GMT</pubDate>
    <dc:creator>Nick Brennan_2</dc:creator>
    <dc:date>2005-03-08T07:26:41Z</dc:date>
    <item>
      <title>Perl script problem - file::find</title>
      <link>https://community.hpe.com/t5/operating-system-linux/perl-script-problem-file-find/m-p/4890093#M69858</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;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....&lt;BR /&gt;&lt;BR /&gt;Am writing a perl admin script, which needs to find a bunch of files passed as parameters to the script:&lt;BR /&gt;&lt;BR /&gt;&lt;FIND_SCRIPT.PL directory="" file1="" file2="" file3=""&gt;&lt;BR /&gt;&lt;BR /&gt;My script basically looks like this:&lt;BR /&gt;&lt;BR /&gt;use strict;&lt;BR /&gt;use File::Find;&lt;BR /&gt;my $dir = "$ARGV[0]" ;&lt;BR /&gt;shift @ARGV;&lt;BR /&gt;foreach (@ARGV) {&lt;BR /&gt;   find(\&amp;amp;wanted, '$dir', '$_');&lt;BR /&gt;}&lt;BR /&gt;sub wanted { /$ARGV[1]/ &amp;amp;&amp;amp; print "$File::Find::name\n;" }&lt;BR /&gt;&lt;BR /&gt;It doesn't work. Have tried various other methods... Can anyone give me a quick pointer how to go about this?&lt;BR /&gt;&lt;BR /&gt;TIA&lt;BR /&gt;Nick&lt;/FIND_SCRIPT.PL&gt;</description>
      <pubDate>Tue, 08 Mar 2005 07:26:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/perl-script-problem-file-find/m-p/4890093#M69858</guid>
      <dc:creator>Nick Brennan_2</dc:creator>
      <dc:date>2005-03-08T07:26:41Z</dc:date>
    </item>
    <item>
      <title>Re: Perl script problem - file::find</title>
      <link>https://community.hpe.com/t5/operating-system-linux/perl-script-problem-file-find/m-p/4890094#M69859</link>
      <description>--8&amp;lt;---&lt;BR /&gt;use strict;&lt;BR /&gt;use File::Find;&lt;BR /&gt;&lt;BR /&gt;sub usage&lt;BR /&gt;{&lt;BR /&gt;print STDERR "usage: $0 dir file ...\n";&lt;BR /&gt;exit;&lt;BR /&gt;} # usage&lt;BR /&gt;&lt;BR /&gt;my $dir = shift;&lt;BR /&gt;-d $dir or usage;&lt;BR /&gt;@ARGV or usage;&lt;BR /&gt;&lt;BR /&gt;my $files = join "|" =&amp;gt; @ARGV;&lt;BR /&gt;$files = qr{$files};&lt;BR /&gt;&lt;BR /&gt;find (sub { m/$files/ and print "$File::Find::name\n" }, $dir);&lt;BR /&gt;--&amp;gt;8---&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn</description>
      <pubDate>Tue, 08 Mar 2005 09:16:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/perl-script-problem-file-find/m-p/4890094#M69859</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2005-03-08T09:16:25Z</dc:date>
    </item>
    <item>
      <title>Re: Perl script problem - file::find</title>
      <link>https://community.hpe.com/t5/operating-system-linux/perl-script-problem-file-find/m-p/4890095#M69860</link>
      <description>Thanks a million. Didn't realise you could run tests without parenthesis either. &lt;BR /&gt;&lt;BR /&gt;(Sorry, am a Perl newbie. What's &lt;QR&gt;?).&lt;BR /&gt;&lt;BR /&gt;Thanks again &lt;BR /&gt;Nick&lt;/QR&gt;</description>
      <pubDate>Tue, 08 Mar 2005 10:07:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/perl-script-problem-file-find/m-p/4890095#M69860</guid>
      <dc:creator>Nick Brennan_2</dc:creator>
      <dc:date>2005-03-08T10:07:26Z</dc:date>
    </item>
    <item>
      <title>Re: Perl script problem - file::find</title>
      <link>https://community.hpe.com/t5/operating-system-linux/perl-script-problem-file-find/m-p/4890096#M69861</link>
      <description>qr is the quote-regex operator, which precompiles the regular expression so it ain't eveluated time after time&lt;BR /&gt;&lt;BR /&gt;Your major `fault' however was the argument passing in&lt;BR /&gt;&lt;BR /&gt;foreach (@ARGV) {&lt;BR /&gt;find (\&amp;amp;wanted, '$dir', '$_');&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;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&lt;BR /&gt;&lt;BR /&gt;second problem you created is to pass '$_', which again should not have been quoted for now obvious reasons, but find takes the following arguments:&lt;BR /&gt;&lt;BR /&gt;find (sub, dir, ...)&lt;BR /&gt;&lt;BR /&gt;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.&lt;BR /&gt;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&lt;BR /&gt;&lt;BR /&gt;for qr, do&lt;BR /&gt;&lt;BR /&gt;# man perlop&lt;BR /&gt;&lt;BR /&gt;search for&lt;BR /&gt;&lt;BR /&gt;       Regexp Quote-Like Operators&lt;BR /&gt;&lt;BR /&gt;to read&lt;BR /&gt;--8&amp;lt;---&lt;BR /&gt;       qr/STRING/imosx&lt;BR /&gt;               This operator quotes (and possibly compiles) its STRING as a&lt;BR /&gt;               regular expression.  STRING is interpolated the same way as&lt;BR /&gt;               PATTERN in "m/PATTERN/".  If "'" is used as the delimiter, no&lt;BR /&gt;               interpolation is done.  Returns a Perl value which may be used&lt;BR /&gt;               instead of the corresponding "/STRING/imosx" expression.&lt;BR /&gt;&lt;BR /&gt;               For example,&lt;BR /&gt;&lt;BR /&gt;                   $rex = qr/my.STRING/is;&lt;BR /&gt;                   s/$rex/foo/;&lt;BR /&gt;&lt;BR /&gt;               is equivalent to&lt;BR /&gt;&lt;BR /&gt;                   s/my.STRING/foo/is;&lt;BR /&gt;--&amp;gt;8---&lt;BR /&gt;&lt;BR /&gt;Hope this helps.&lt;BR /&gt;Enjoy, Have FUN! H.Merijn</description>
      <pubDate>Tue, 08 Mar 2005 10:32:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/perl-script-problem-file-find/m-p/4890096#M69861</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2005-03-08T10:32:11Z</dc:date>
    </item>
    <item>
      <title>Re: Perl script problem - file::find</title>
      <link>https://community.hpe.com/t5/operating-system-linux/perl-script-problem-file-find/m-p/4890097#M69862</link>
      <description>Rather helpful stuff from contributors. Thank God for the HP forums........</description>
      <pubDate>Thu, 10 Mar 2005 05:50:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/perl-script-problem-file-find/m-p/4890097#M69862</guid>
      <dc:creator>Nick Brennan_2</dc:creator>
      <dc:date>2005-03-10T05:50:29Z</dc:date>
    </item>
  </channel>
</rss>

