in reply to Getting rid of a temporary variable in AoH
Once the @fields array is declared inside the loop, you can safely destroy it:
while ( my $line = <DATA> ) { chomp $line; my @fields = qw( login uid gid name home + shell ); my @items = $line =~ /^([\-\w]+):x:(\d+):(\d+):([\-\w\s\(\)\,]*):([\w\/]+) +:([\w\/]+)$/ or die "Malformed input [$line]"; push @users, {}; $users[-1]{ shift @fields } = shift @items while @fields; }
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Getting rid of a temporary variable in AoH
by AnomalousMonk (Archbishop) on Jun 12, 2013 at 02:58 UTC |
In Section
Seekers of Perl Wisdom