in reply to Getting rid of a temporary variable in AoH
Interesting, I was also thinking of yesterday's "splice/mesh" discussion. (I wouldn't really do it this way.)
But do notice in your RE, I changed delimiter and did not escape forward slashes, commas or hyphens.
use strict; use warnings; use List::MoreUtils qw(mesh); use Data::Dumper; my @users; my @fields = qw(login uid gid name home shell); while (<DATA>) { m#^\s*([\w-]+):x:(\d+):(\d+):([\w\s\(\),-]*):([\w/]+):([\w/]*)$# or die "Malformed input [$_]"; push @users, { mesh @fields, @{[//]} }; } print Dumper \@users; __DATA__ root:x:0:0::/:/usr/bin/ksh paul:x:201:1::/home/paul:/usr/bin/ksh jdoe:x:202:1:John Doe:/home/jdoe:/usr/bin/ksh
Update: The parens don't need to be escaped either:
m#^\s*([\w-]+):x:(\d+):(\d+):([\w\s(),-]*):([\w/]+):([\w/]*)$#
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Getting rid of a temporary variable in AoH
by Arunbear (Prior) on Jun 11, 2013 at 15:53 UTC | |
|
Re^2: Getting rid of a temporary variable in AoH
by hdb (Monsignor) on Jun 11, 2013 at 15:14 UTC |