differences between find2perl and find

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

first of all i don't know if this is the proper group to discuss this
problem, but i can't find a better one.....

I'm using "SunOS h213 5.9 Generic_122300-29 sun4u sparc SUNW,Sun-
Fire-15000" (uname -a) and perl v5.6.1 and want to copy a lot of files
to a remote host. So i'm looking up for those files using find:

rsync -avz `find * -prune -type d -mtime -30|grep -v archive`

To add some funtionality (logging, mail if completed e.g) i'd like to
do this with perl.
Now i gonna try to convert find to a perl script using find2perl.....

and will have some problems:
gm@h213:/tmp ># redirect STDERR to avoid warnings caused by
gm@h213:/tmp >find * -prune -type d -mtime -30 2>/dev/null | tail -2
gm@h213:/tmp >
gm@h213:/tmp >find2perl  -prune -type d -mtime -30 | perl
Found = in conditional, should be == at - line 26.
gm@h213:/tmp >

line 26 is that one with prune-check, but if using only -prune those
error does not occur (but i still have different results)

gm@h213:/tmp >find * -prune 2>/dev/null | tail -2
gm@h213:/tmp >find2perl  -prune  | perl
gm@h213:/tmp >

One solution for me is to glob "*". As far as i can see glob "*" and
`find * -prune` will produce the same output. So i will be able to
find the files i need by 'grep {(-d $_ && (int(-M $_) <30))} glob "*"'

But that's not that what i want to use. If i've tools like find2perl i
wanna use those ones.

So what's the problem and how can i use the find2perl-result.
Do you know what's to do?


p.s. enclose the output of 'find2perl * -prune -type d -mtime -30'

gm@h213:/tmp >find2perl * -prune -type d -mtime -30
#! /usr/local/bin/perl -w
    eval 'exec /usr/local/bin/perl -S $0 $'
        if 0; #$running_under_some_shell

use strict;
use File::Find ();

# Set the variable $File::Find::dont_use_nlink if you're using AFS,
# since AFS cheats.

# for the convenience of &wanted calls, including -eval statements:
use vars qw/*name *dir *prune/;
*name   = *File::Find::name;
*dir    = *File::Find::dir;
*prune  = *File::Find::prune;

# Traverse desired filesystems
File::Find::find({wanted => \&wanted}, **** list of files **** );

sub wanted {
    my ($dev,$ino,$mode,$nlink,$uid,$gid);

    ($File::Find::prune = 1) &&
    (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
    -d _ &&
    (int(-M _) < 30);

gm@h213:/tmp >

Re: differences between find2perl and find

Quoted text here. Click to load it

As far as find2perl:

-prune is going to stop it from enterring sub-direcoties in the found directory.
This is more of a mechanism to operate on a single directory that are found in
the direcoties list. So even if you want to examine the directories under
the current one, this prevents it. Therefore its totally useless in this context.

Quoted text here. Click to load it
This is not something like glob '*'.

Quoted text here. Click to load it

find2perl dir1 dir2 dir3 file1 -prune -type d -mtime -30
File::Find::find({wanted => \&wanted}, 'dir1', 'dir2', 'dir3', 'file1'  );

and there doesen't appear to be any other way to to get a system generated
list. In fact because of this, find2perl is not that usefull in this context.
Its ok for generating a prototype wanted() which you can manipulate and execute
as a standalone script.

The documentation for find is pretty bizarr and not much explanation or examples.
Its all about magic and hocus-pocus.

From the find2perl docs (on the bottom):
" ... or if you use the warnings pragma,
File::Find will report warnings for several weird situations..."

If you want to turn off warnings if piping the find2perl output to perl,
just add this:

find2perl * -prune -type d -mtime -30 | perl -M-warnings

Good luck. I'm not too suprised there were no responses.

Re: differences between find2perl and find

On 28 Aug., 22:28, s...@netherlands.com wrote:

Quoted text here. Click to load it

but there is one that helps (--> perl -M-warnings)


by thw way ... i was a little bit confused by that difference => find
does not needs -print to print out files found, find2perl will not
print anything without this option

Re: differences between find2perl and find

Quoted text here. Click to load it

Traditionally find *did* need -print to print out the files found. Now
it is optional, but the find2perl utility is quite old and probably
understands only find syntax from the 1980's.


Re: differences between find2perl and find

Quoted text here. Click to load it

Note that there is a very important difference between your call to find
and your call to find2perl:


find * -prune ...

the * will be expanded to all files in the current directory (except
those starting with "."). So here you really call

find a_dir file1 file2 tmpdir.21790 tmpdir.27721 whatever -prune ...

But in

find2perl  -prune ...

you don't give any file arguments. So this is equivalent to

find2perl . -prune ...

If you call

find . -prune ...

you probably will get the same results.

To get the same same result as with your find command, you could call

find2perl * -prune ...

but that would include the list of currently existing files in your
script which almost certainly means that the script is useless the next
time you want to run it (I assume that 'find2perl  -prune -type d -mtime
-30 | perl' is only used for demonstration purposes. Normally you would
save the script into a file and run it several times).

So you need to get the glob('*') that is normally performed by the shell
into you script:

Quoted text here. Click to load it
                     replace this with
Quoted text here. Click to load it


Site Timeline