in reply to how to assign output of Find() into a variable $
There are many many ways to do that trick. One way is to wrap a call to the callback sub and pass a "return" parameter into it:
#!/usr/bin/perl use warnings; use strict; use File::Find; my @filtered = 'aaa/'; my @results; find(sub {callback(\@results)}, @filtered); print "$_\n" for @results; sub callback { my ($results) = @_; push @$results, $File::Find::name if /\.pl$/; }
There are variations on the theme that involve using global variables in various ways or variations that work well with object oriented techniques. Avoiding globals is good for maintainable code and the object oriented variations tend to be trivial changes to the code shown.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: how to assign output of Find() into a variable $
by Tux (Canon) on May 18, 2016 at 09:30 UTC | |
by GrandFather (Saint) on May 18, 2016 at 09:37 UTC | |
|
Re^2: how to assign output of Find() into a variable $
by BillKSmith (Monsignor) on May 18, 2016 at 13:21 UTC | |
by GrandFather (Saint) on May 18, 2016 at 21:23 UTC |