Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

find2perl Linux vs AIX

by TechFly (Scribe)
on Dec 08, 2010 at 15:53 UTC ( #876054=perlmeditation: print w/ replies, xml ) Need Help??

I don't know if anyone else has had this sort of problem, but I am fairly new to Perl, and very new to using modules, and such. I purchased the book 'Automating System Administration with Perl' (O'Reilly) and it talks about the find2perl script. This seemed kind of neat, and I had need for a find style script, so I played around with it. The first thing I notices was that I kept getting an error at runtime. It would say something like this:
Use of uninitialized value in chdir at ./tempfind.pl line 48. Use of chdir('') or chdir(undef) as chdir() is deprecated at ./tempfin +d.pl line 48. -rw------- 1 mcafee mcfav 78323091 Nov 16 20:05 /home/mcafee/ +updates/avvdat-6169.zip
I did it on my Slackware 13.1 (Linux 2.6.27.7-SMP) box, and did not get the messages. After a bit of digging, I found that there is a chdir command that is in the wrong place. The place it was put would not ever be executed because of an exit command! Move the two lines, and everything is peachy.
#! /usr/opt/perl5/bin/perl -w eval 'exec /usr/opt/perl5/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; sub wanted; sub doexec ($@); # Traverse desired filesystems File::Find::find({wanted => \&wanted}, '/home/mcafee/updates'); exit; <<----Ends the script sub wanted { /^avvdat-.?.?.?.?\.zip\z/s && doexec(0, 'ls','-al','{}'); } #These two lines are outside of the subroutines, and fall after the ex +it, so they will never be executed! use Cwd (); #<<-----Move this up to the use File::Find at the beginnin +g of the code. my $cwd = Cwd::cwd(); #<<-----Put this right under it. sub doexec ($@) { my $ok = shift; my @command = @_; # copy so we don't try to s/// aliases to consta +nts for my $word (@command) { $word =~ s#{}#$name#g } if ($ok) { my $old = select(STDOUT); $| = 1; print "@command"; select($old); return 0 unless <STDIN> =~ /^y/; } chdir $cwd; #sigh system @command; chdir $File::Find::dir; return !$?; }
This may, or may not ever affect anyone else, but I thought it was interesting. I looked at the code in the slack box versus the AIX box, and the headers are the same (with no version info, but a number of change lines), but the content has some differences. I am finding that the content of my Linux and AIX boxes are very different perl-wise. I don't know if this difference is because of the AIX being Perl 5.8.2, and Linux being 5.10.0. Either way, enough of my rambling.

Comment on find2perl Linux vs AIX
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://876054]
Approved by marto
Front-paged by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (14)
As of 2014-12-21 05:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (103 votes), past polls