Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^3: Listing Files

by dreadpiratepeter (Priest)
on Sep 16, 2011 at 11:48 UTC ( #926390=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Listing Files
in thread Listing Files

Why don't you post what you have tried? Then we can help you fix it. This is not a code writing service and the posts above should be enough to get you started.



-pete
"Worry is like a rocking chair. It gives you something to do, but it doesn't get you anywhere."


Comment on Re^3: Listing Files
Re^4: Listing Files
by vchavan (Initiate) on Sep 17, 2011 at 06:23 UTC
    use strict; use warnings; use File::Find; find({ wanted => \&process_file, preprocess => \&preprocess, no_chdir +=> 1 }, @ARGV); #find({ wanted => \&process_file, no_chdir => 1 }, @ARGV); sub process_file { @List = (); if (-f $_) { print "This is a file: $_\n"; push(@List,$_); } else { print "This is not file: $_\n"; } return @List; } sub preprocess { print "pre-processing @_\n"; # never see this return sort @_; } @DIRLIST = @List; print "@DIRLIST\n";

    I am trying to return List of Files from File:Find to main Module in @DIRLIST But do not know if it is possible to return a value from wanted sub in File:Find to main sub

      Just create your list variable in the main scope of your script, so it'll be in scope inside the sub:

      my @list; find( \&wanted, '.'); say for @list; sub wanted { return unless -f; push @list, $File::Find::name; }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://926390]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (17)
As of 2015-07-02 18:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (44 votes), past polls