Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

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 ./ line 48. Use of chdir('') or chdir(undef) as chdir() is deprecated at ./tempfin line 48. -rw------- 1 mcafee mcfav 78323091 Nov 16 20:05 /home/mcafee/ +updates/
I did it on my Slackware 13.1 (Linux 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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://876054]
Approved by marto
Front-paged by ww
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (8)
As of 2018-06-19 13:13 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (114 votes). Check out past polls.