in reply to simplify the code

You don't need all those temporary variables in your loop,

for (@$sur) { my $firstrow = join '<-->', @{$_}{qw/one two four/}; $hash1{$_->{'three'}} .= $hash1{$_->{'three'}} ? '####'.$_->{'four'} : $firstrow; }

Update: The whole loop in a single statement:

$hash1{$_->{'three'}} .= $hash1{$_->{'three'}} ? '####' . $_->{'four'} : join( '<-->', @{$_}{qw/one two four/}) for @$sur;
No temporaries at all.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^2: simplify the code
by Zed_Lopez (Chaplain) on Oct 09, 2005 at 15:14 UTC

    I wrote basically the same solution, but like having the loop variable (esp. since there's a use of $_ in the map.)

    We both changed the conditional in different ways, from ne '' in the original to evaluates true in yours, and to existence in mine.

    for my $hashref (@$sur) { if (exists $hash1{$hashref->{three}}) { $hash1{$hashref->{three}} .= "####$hashref->{four}"; } else { $hash1{$hashref->{three}} = join '<-->', map $hashref->{$_}, (qw(o +ne two four)); } }
Re^2: simplify the code
by Aristotle (Chancellor) on Oct 09, 2005 at 16:41 UTC

    The second one looks quite intimidating, IMHO. The first one could be clearer if you chose your temporary variables just a tad better. The code I ended up writing looks is almost identical to your first loop, except for the choice of temporaries; and I think it looks a lot clearer.

    Makeshifts last the longest.