in reply to Getting rid of a temporary variable in AoH
For you to judge whether this is an improvement ;)
use strict; use warnings; use Data::Dumper; use List::MoreUtils qw( mesh ); my @users = map { { mesh @{[ qw( login uid gid name home shell ) ]}, @{[ /^([\-\w]+):x:(\d+):(\d+):([\-\w\s\(\)\,]*):([ +\w\/]+):([\w\/]+)$/ ]} } } <DATA>; print Dumper \@users; __DATA__ hdb:x:1111:2222:hdb:/home/hdb:/bin/bash
UPDATE: Above is too complicated, look at this:
use strict; use warnings; use Data::Dumper; my @users = map { /^([\-\w]+):x:(\d+):(\d+):([\-\w\s\(\)\,]*):([\w\/]+):([\w\/]+)$/; { login => $1, uid => $2, gid => $3, name => $4, home => $5, shell = +> $6 } } <DATA>; print Dumper \@users; __DATA__ hdb:x:1111:2222:hdb:/home/hdb:/bin/bash
|
|---|