Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Perl
Perl Misc
Passing paramaters to the File::Find find() function
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="niall.macpherson, post: 4809277"] I've just used the File::Find module for the first time. I can't figure out how to pass variables into the find() function. Here is a trivial example (I know that what this does can be done many other better ways, but it was about the smallest bit of code that I could come up with which illustrates my problem) The point is that $mytext and @myfiles both have to be global variables since there doesn't seem to be a way of passing them from the testclpm7() sub to the pushfiles() sub via the find() call. Is it possible to pass values through so I can avoid having to use global variables ? Thanks use strict; use warnings; use File::Find; use Data::Dumper; use vars qw (@myfiles); use vars qw ($mytext); #----------------------------------------------------------- sub pushfiles { if(!/$mytext/) { push @myfiles, $File::Find::name; } return; } #----------------------------------------------------------- sub testclpm7 { ($mytext) = @_; ## Works but I would like to pass both $mytext and @myfiles ## here so that they don't have to be global find (\&pushfiles , "C:/develop/NiallPerlScripts"); print Dumper \@myfiles; } #----------------------------------------------------------- if($#ARGV != 0) { die "Usage $0 <text>"; } testclpm7($ARGV[0]); [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Perl
Perl Misc
Passing paramaters to the File::Find find() function
Top