> -----Original Message-----
> From: Rupert Heesom [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, July 11, 2002 5:54 AM
> To: 'Bob Showalter'
> Cc: [EMAIL PROTECTED]
> Subject: RE: Easy way to compare 2 perl lists (arrays)?
>
>
> Bob:
>
> I like your efficient solution, but I want to clarify what's actually
> happening in the line, especially the grep stuff.
> I know the { s// } is a substitution regexp. It's looking for a
> filename ending in ".tiff", then substituting ".pdf" for ".tiff".
> To me the subst regexp looks like a file rename. If it's
> not, how do I
> interpret such a regexp?
Here's the one-liner again:
$ perl -le 'print $_ for grep { s/\.tiff$/.pdf/ && !-f } @ARGV' *.tiff
> The "&& !-f" I think means "and do not look for file input".
The -f is a "file exists" test, so !-f means "file doesn't exist".
Which file? Since I didn't specify a file name after -f, the default
of $_ is used. So this part of the expression is true if the file
named in $_ does not exist.
The s/// operation is changing $_ so that it ends with .pdf instead
of .tiff
So the stuff inside the braces says:
1. Change the value in $_ to end with .pdf instead of .tiff
2. See if a file of that name (with .pdf) doesn't exist
If both parts are true, the condition of the grep() is true, and $_
is added to the output list from grep().
So, grep() gets an input list of .tiff file names, changes the
string to .pdf and checks for the non-existence of that file. It
spits out the list of missing (non-existing) .pdf file names.
>
> The "@ARGV" I assume takes the command line parameter which I
> assume is
> the directory to look in for the files.
@ARGV will be the list of .tiff files provided by the shell
>
> The last bit: "*.tiff" is probably looking for the TIFF files to base
> the compare/search on.
This will be expanded by the shell into a list of files. Actually, you
could use just "*", since non .tiff files will fail the first part of
the condition for grep and will not be examined. But this would slow
down the grep unecessarily.
You could also bypass @ARGV and use a glob:
$ perl -le 'print $_ for grep { s/\.tiff$/.pdf/ && !-f } <*.tiff>'
HTH
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]