Kevin Pfeiffer wrote: > I've taken a tip from File::Find and am doing this: > > scan_mb(\&wanted, $quiz_mb); > # $quiz_mb contains a pathname to a directory > > (Note this is a small task similar to the newest qotw from MJD) > > I am reading a directory and foreach filename running my function > &wanted. So, taking a tip from File::Find I am passing a reference to > the wanted function to scan_mb. Now, inside sub scan_mb, how do I > regain/use this passed function?
If you call it like: scan_mb(\&wanted, $quiz_mb); Then you use it like: sub scan_mb { my ($subref, $dir) = @_; &$subref('args', 'list', 'here'); } > > For now I'm simply cheating... (i.e. since the function lives in > main, I simply call it and ignore the passed reference.) :-) > > sub scan_mb { > > for ( <$_[1]/*> ) { > next unless (-f $_); > /^.*\/(.*)$/; > wanted($_); > } > } > > Or, since both functions are in the same scope(?), perhaps passing a > reference is pointless (other than as a good learning exercise)? You would use the reference when: 1. You will be calling scan_mb with *different* values for $coderef throughout your program. 2. scan_mb is in a library designed to be used with various programs, each of which must supply a specific function for wanted(). That's why File::Find does it this way. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]