pvaldes has asked for the wisdom of the Perl Monks concerning the following question:
I'm perplexed. Can you tell me what is wrong with this script?
#!/usr/bin/perl -w use strict; use warnings; use diagnostics; use File::Find; open (my $t, '>', '/home/myuser/myfilename.sql') or die $!; print $t "blah blah\n"; find( { preprocess => \&hi, wanted => \&work, postprocess => \&bye, fo +llow_skip => 1 }, "."); sub hi { print $t "hi\n"; return;} # works correctly sub bye { print $t "bye\n"; return;} # works correctly sub work { print "my name is: ", $File::Find::name; print $t "I'm a file!"; return;} close $t;
when I run the script in the current tree directory I would expect a list of filenames being printed in screen and a text file containing:
blah blah hi I'm a file!I'm a file!I'm a file!... etc bye
But what I have is: "my name is: ." or "my name is: 1" and a file containing:
blah blah hi bye I'm a file! <-yep, solitary and in the wrong position
libfile-find-wanted-perl/testing,testing,now 1.00-1.1 all installed, automatic
Can somebody tell me what is happening here? Is not a little late for an 1-April Joke?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Strange behavior in File::Find (stopped working for no reason)
by choroba (Cardinal) on Apr 12, 2021 at 16:58 UTC | |
by pvaldes (Chaplain) on Apr 12, 2021 at 17:08 UTC | |
|
Re: Strange behavior in File::Find (stopped working for no reason)
by pvaldes (Chaplain) on Apr 12, 2021 at 16:58 UTC |