differences between find2perl and find

G

GU

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`
user@remote:dir

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
permissions
gm@h213:/tmp >find * -prune -type d -mtime -30 2>/dev/null | tail -2
tmpdir.21790
tmpdir.27721
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
wkz_adj_maf
wkz_adj_rep.csv
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?

Thanks
gerhard


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 ${1+"$@"}'
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 **** );
exit;


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 >
 
S

sln

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


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 >

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.
find2perl * -prune -type d -mtime -30
^
This is not something like glob '*'.
File::Find::find({wanted => \&wanted}, **** list of files **** );

find2perl dir1 dir2 dir3 file1 -prune -type d -mtime -30
does
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.
-sln
 
G

Gerhard

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

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

thanks

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
 
P

Peter J. Holzer

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

thanks

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

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.

hp
 
P

Peter J. Holzer

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
permissions
gm@h213:/tmp >find * -prune -type d -mtime -30 2>/dev/null | tail -2
tmpdir.21790
tmpdir.27721
gm@h213:/tmp >
gm@h213:/tmp >find2perl -prune -type d -mtime -30 | perl

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

In

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:
#! /usr/local/bin/perl -w
eval 'exec /usr/local/bin/perl -S $0 ${1+"$@"}'
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 **** );
^^^^^^^^^^^^^^^^^^^^^^^
replace this with
glob("*")
or
@ARGV

hp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top