in reply to Generation of Array of hashes by reading a file
Doing a two step via flag is not needed
#!/usr/bin/perl use warnings; use strict; use Data::Dumper; ################ my @AoH; my $rec; open my $fh, '<', 'interface.txt' or die; while (<$fh>) { chomp; if (/^(\w+\d{1}):\s+flags=(.*?>)/) { $rec = {}; push @AoH, $rec; $rec->{'interface'} = $1; $rec->{'flags'} = $2; } elsif (/ether\s+(.*$)/) { $rec->{'ether'} = $1; } elsif (/media:\s+(\w+)/) { $rec->{'media'} = $1; } elsif (/inet\s+(\w+\.\w+\.\w+\.\w+)/) { $rec->{'inet'} = $1; } elsif (/status: (\w+)/) { $rec->{'status'} = $1; } } close($fh); print Dumper \@AoH;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Generation of Array of hashes by reading a file
by NetWallah (Canon) on Jan 04, 2018 at 21:27 UTC | |
|
Re^2: Generation of Array of hashes by reading a file
by pr33 (Scribe) on Jan 04, 2018 at 21:58 UTC | |
by choroba (Cardinal) on Jan 04, 2018 at 23:21 UTC | |
by pr33 (Scribe) on Jan 05, 2018 at 00:00 UTC |