reisinge has asked for the wisdom of the Perl Monks concerning the following question:
Hello, how can I leave out the temporary %users variable?
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my @users; while ( my $line = <> ) { chomp $line; my @fields = qw( login uid gid name home + shell ); $line =~ /^ ([\-\w]+):x:(\d+):(\d+):([\-\w\s\(\)\,]*):([\w\/]+) +:([\w\/]+)$/x or die "Malformed input [$line]"; my %users; @users{@fields} = ($1, $2, $3, $4, $5, $6); push @users, \%users; } print Dumper \@users;
Update: any other code improvements are welcome ... :-)
Well done is better than well said. -- Benjamin Franklin
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Getting rid of a temporary variable in AoH
by choroba (Cardinal) on Jun 11, 2013 at 14:08 UTC | |
by AnomalousMonk (Archbishop) on Jun 12, 2013 at 02:58 UTC | |
|
Re: Getting rid of a temporary variable in AoH
by Corion (Patriarch) on Jun 11, 2013 at 14:07 UTC | |
|
Re: Getting rid of a temporary variable in AoH
by hbm (Hermit) on Jun 11, 2013 at 14:56 UTC | |
by Arunbear (Prior) on Jun 11, 2013 at 15:53 UTC | |
by hdb (Monsignor) on Jun 11, 2013 at 15:14 UTC | |
|
Re: Getting rid of a temporary variable in AoH
by hdb (Monsignor) on Jun 11, 2013 at 14:36 UTC | |
|
Re: Getting rid of a temporary variable in AoH
by ww (Archbishop) on Jun 11, 2013 at 14:04 UTC |