Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Can you help me figure out why the code isn't working as I expect? I am using Perl 5.005_03 on AIX.#!/usr/bin/perl use File::Find; my $old_flag = 0; find ( { wanted => \&process, preprocess => \&preprocess, postprocess => \&postprocess }, '/home/greg/mydir' ); sub process { print "Processing\n"; if (/.*\.old$/) { $old_flag = 1; } } sub preprocess { print "Pre-Processing\n"; my @file_list = @_; $old_flag = 0; return @file_list; } sub postprocess { print "Post-Processing\n"; my $old_CPB = "CPB.old"; my $new_CPB = "CPB"; if ($old_flag == 1) { if (rename $new_CPB, $old_CPB) { open IN, $old_CPB or die "Unable to open input CPB: $!"; open OUT, ">$new_CPB" or die "Unable to open output CPB: $!"; while (<IN>) { chomp; if (/^cat.*/) { print OUT "cat\t/kat/src/all/bld_pipe.4go \\\n"; s/^cat\t/\t/; } print OUT "$_\n"; } } else { #not found return; } } close IN; close OUT; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: File::Find problem
by converter (Priest) on Mar 17, 2003 at 20:01 UTC | |
|
Re: File::Find problem (yucky callbacks)
by tye (Sage) on Mar 19, 2003 at 08:19 UTC | |
by zby (Vicar) on Mar 19, 2003 at 08:45 UTC | |
by tye (Sage) on Mar 19, 2003 at 09:29 UTC | |
|
Re: File::Find problem
by pg (Canon) on Mar 17, 2003 at 17:06 UTC | |
by Anonymous Monk on Mar 17, 2003 at 17:44 UTC | |
|
Re: File::Find problem
by arturo (Vicar) on Mar 17, 2003 at 17:41 UTC | |
|
Re: File::Find problem
by clairudjinn (Beadle) on Mar 17, 2003 at 17:44 UTC | |
by converter (Priest) on Mar 17, 2003 at 18:29 UTC | |
|
Re: File::Find problem
by Aristotle (Chancellor) on Mar 20, 2003 at 20:26 UTC |