Edit: Added missing 'push' to code example.

On Nov 28, 2009, at 14:13, Jeremiah Foster wrote:

> Hi there!
> 
>       This may or may not be a beginners question. If not, please let me know 
> where I ought to post. :-)
> 
>       I have a data structure, a simple array. It is made up of sections of 
> files I have slurped;
> 
>       sub _build_packages { 
>          use Perl6::Slurp; 
>          my @pkgs; 
> 
>           # iterate over the packages slurping them into one 
>          map { push @pkgs, (slurp $_, {irs => qr/\n\n/xms}) } @packages; 
>           return \...@pkgs; 
>        } 
> 
>       (The above code is in the class declaration)
> 
> 
>       Now in my program which subclasses that array ref, after de-referencing 
> I have this idiom;
> 
>       my %versions;
>        map { 
>        my $package = $_;
>        # autovivfy a hash with versions of packages 
>          $versions{$package} = [ ] unless exists $versions{$package};
           push @{ $versions{$package} = $version
         } @packages
> 
> 
>       So my questions are:
> 
>       Is this an efficient way to do this? Am I using the idiom correctly? 
> Could I make it more readable? Is my predilection for map over foreach making 
> this less readable? Or is that only a question of style?
> 
>       Thanks for any feedback.
> 
>       Regards,
> 
>       Jeremiah
> 
> 
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
> 
> 
> 


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to