Jose Nyimi wrote:
Gunnar Hjalmarsson wrote:
Marcos Rebelo wrote:
Gunnar Hjalmarsson wrote:
#!/usr/bin/perl
use strict;
use warnings;
open my $GROUPS, 'File1' or die $!;
open my $USERS, 'File2' or die $!;
my %groups;
chomp and $groups{$_} = [] for <$GROUPS>;
while ( <$USERS> ) {
my ($user, @groups) = split;
$groups{$_} and push @{ $groups{$_} }, $user for @groups;
}
for ( sort keys %groups ) {
print "$_:\n", ( join "\n", @{ $groups{$_} } ), "\n\n";
}
__END__
It seems to me that Olakunle Banjo shall not be an Perl Expert.
What's your point? Are you assuming he is here for some other
reason but learning Perl?
Can you also explain him the code?
If there is anything specific in the code that you, Olakunle or
somebody else do not understand by help of the Perl docs, I'll be
happy to explain.
Gunnar, your code is clean, powerfull and maintainable ...
I wouldn't write it in an other way even though TIMTOWTDI :-)
Thanks!
It's not good pratice avoid using perl's flexibility and write
"bad" code just to make your code "understandable" to non perl
experts.
In contrary use good perl's features that will allow non experts to
learn from you.
Hmm.. First, I'm a beginner level Perl hobbyist, not an expert, so per
definition I'm not able to write code for "experts".
I'm not sure if Marcos considered my code, in contrast to David's
code, difficult to understand, or if he 'objected' to both
suggestions. Actually, the approach is the same, even if I skipped the
file scoped @groups array and a few temporary variables and avoided
some redundant typing.
To those who are not familiar with Perl data structures, and since
both the suggestions include a hash of arrays, it may indeed be tricky
to understand what's happening without reading up about it. OTOH, a
hash of arrays is a natural approach to the problem in question.
Besides that, I don't know...
But please believe that I do not try to deliberately make my code
difficult to understand, and I'm honestly interested in knowing what
it is in this code that made Marcos (and possibly others) start
talking about "experts".
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>