From: Kevin Pfeiffer <[EMAIL PROTECTED]>
> I'm doing an exercise with coderefs and wondering if there is much
> difference between my answer and the one given...
> 
> Here is my subroutine that returns two coderefs...
> 
> sub gather_mtime_between {
>    my ($start, $stop) = @_;
>    my @files = ();
>    return (sub {
>          my $timestamp = (stat $_)[9];
>          if ( -f and $timestamp >= $start and $timestamp <= $stop) {
>             push @files, $File::Find::name;
>          }
>       },
>       sub { return @files });
> }
> 
> The answer given is almost identical (but with error checking for the
> stat call). But it includes variables for the subroutines...
> 
> sub gather_mtime_between {
>    # etc.
>    my $gatherer = sub { #first coderef variable
>       # sub much the same
>    }
>    my $fetcher = sub { # second
>       # same
>    }
> }
> 
> In both cases the sub is called like this:
> my($gatherer, $yield) = gather_mtime_between($start, $stop);
> 
> As I understand this, mine returns two anonymous coderefs and the
> given answer assigns the coderefs to two variables whose contents are
> then returned (and these two variable names go immediately out of
> scope)? Is there any reason to use the variables here?

Just readability. It doesn't make any difference from the outside.

> And while I'm wasting bandwidth... this subroutine needs to always
> come first -- or be in a BEGIN block?

No. You can treat the sub just like any other.

Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to