From:                   Rob Dixon <[EMAIL PROTECTED]>
> Jenda Krynicky wrote:
> > It's just a matter of one map():
> > 
> > #!perl
> > use XML::Generator;
> > 
> > $ref = {
> >     'dermot' => '10',
> >     'joe' => '17',
> >     'rose' => '11',
> >     'phil' => '13',
> >     'brian' => '20',
> >     'andy' => '15',
> > };
> > 
> > my $gen = XML::Generator->new(':pretty');
> > my $xml = $gen->users(
> >      map { $gen->user({id => $ref->{$_}}, $_) } keys %{$ref}
> > );
> > 
> > print $xml;
> > __END__
> 
> Well yes, of course that's possible. But you're advocating abandoning
> strictures and writing unintelligible code by proposing it.

Beg your pardon? use strict doesn't have any problems with that code. 
And if you find map{} uninteligible it's your problem, not the 
code's. If you insist on not using map{} you could of course write 
the code like this:

#!perl
use strict;
use warnings;
use XML::Generator;

my $ref = {
  'dermot' => '10',
  'joe' => '17',
  'rose' => '11',
  'phil' => '13',
  'brian' => '20',
  'andy' => '15',
};

my $gen = XML::Generator->new(':pretty');
my @users;
foreach (keys %{$ref}) {
  push @users, $gen->user({id => $ref->{$_}}, $_)
}

my $xml = $gen->users(
     @users
);

print $xml;
__END__

but I do not find it any easier to read. Just the opposite.

map{} just transforms a list, what's so hard about it?

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]
http://learn.perl.org/


Reply via email to