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.

In reply to find2perl Linux vs AIX by TechFly

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.