Fouled Script

Keary Suska aksuska at webflyer.com
Tue Jan 8 11:30:11 CST 2002


This is a problem with the find command. You must escape the parens to the
shell, which looks like what you intend, but in Perl the use of double
quotes causes the escapes to be unescaped. Try:

$MFILES = "find $MDIR -type f -ls -xdev -fstype ext2 \\( -iname '*personal*'
-o -iname '.*personal*' \\) -print";

Also be aware that the -ls action will provide extraneous information to the
file name, so if you plan to manipulate the file in your script you might
have to extract the file name or simply not use -ls.

Keary Suska
Esoteritech, Inc.
"Leveraging Open Source for a better Internet"

> From: SoloCDM <deedsmis at aculink.net>
> Reply-To: deedsmis at aculink.net, pikes-peak-pm-list at happyfunball.pm.org
> Date: Tue, 08 Jan 2002 04:24:07 -0700
> To: "Pikes Peak Perl Mongers (Majordomo)"
> <pikes-peak-pm-list at happyfunball.pm.org>
> Cc: Eric Schwartz <emschwar at pcisys.net>, Harry Schroeder <has3 at usa.net>, Steve
> Smythe <ssmythe at docent.com>
> Subject: Re: Fouled Script
> 
> Eric Schwartz stated the following:
>> 
>> On Mon, Jan 07, 2002 at 12:25:24AM -0700, SoloCDM wrote:
>> 
>>> The attached script is my first attempt at some means of perl
>>> scripting, base on your advice.  It won't work.  I keep getting the
>>> following error:
>> 
>>> syntax error at ./find-perl-sample2 line 8, near "open " Execution
>>> of ./find-perl-sample2 aborted due to compilation errors.
>> 
>> Unquoted string "directory" may clash with future reserved word at
>> find-perl-sample line 4.  Scalar found where operator expected at
>> find-perl-sample line 5, near "$MFILES" (Missing semicolon on previous
>> line?) syntax error at find-perl-sample line 5, near "$MFILES "
>> find-perl-sample had compilation errors.
>> 
>> Essentially, you're missing a bunch of semicolons, and if [directory]
>> isn't what you really put there, you should tell us, so we know
>> what you actually are asking about.  Otherwise, you should quote it
>> properly.  Furthermore, by using [directory], you're creating an
>> arrayref, and I don't think that's what you wanted to do there.
> 
> Now I am getting the error below with the attached file:
> 
> sh: -c: line 1: syntax error near unexpected token `('
> sh: -c: line 1: `find / -type f -ls -xdev -fstype ext2 ( -iname
> '*personal*' -o -iname '.*personal*' ) -print'
> 
> I hope all the semicolons are in place; although, previously to
> sending the first posting -- I put all the semicolons as expected, but
> I still didn't get a correct response from the script.
> 
> -- 
> Note: When you reply to this message, please include the mailing
> list/newsgroup address and my email address in To:.
> 
> *********************************************************************
> Signed,
> SoloCDM
> #!/usr/bin/perl -w
> #
> 
> $MDIR = "/";
> $MFILES = "find $MDIR -type f -ls -xdev -fstype ext2 \( -iname '*personal*' -o
> -iname '.*personal*' \) -print";
> 
> open FIND, "$MFILES |" or die $!;
> while( <FIND> ) {
> # $_ will have each file name found with full path name
> # do what you want with it here
> print "$_\n";
> }
> close FIND;
> 




More information about the Pikes-peak-pm mailing list