Marcos Rebelo wrote:
Gunnar Hjalmarsson wrote:
Or a little shorter:

#!/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.


Note: Usually is good policy closeing the opened files.

If I have understood it correctly (please correct me if I'm wrong), when you use a my() declared filehandle reference, closing is done automatically when you go out of scope (in this case: when the script exits), and since I'm not interested in possible error messages, I'm not aware of any good reason for closing the filehandles explicitly.


Are you?

--
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>




Reply via email to