in reply to Storing the log file name as key/value in hash
There are better and more secure ways of exporting and then re-importing data than using some sort of eval{}. Consider according to your question:
#!usr/bin/perl use strict; use warnings; use Data::Dumper; my %results; #a hash of array's, (hash key refs an array) print "Input Data parsed into 3 columns:\n"; while (my $line = <DATA>) { chomp $line; my ($text, $ip_thing, $IP_host) = $line =~ /^([^.]+)\.(.*?)\.(IP.*)/; printf ("Data: %-25s %-20s %-s\n", $text,$ip_thing,$IP_host); push @{$results{$ip_thing}},$text; } print "\n"; print "Dumping each hash key's value(s):\n"; foreach my $key (keys %results) { print "$key =>", join (", ", @{$results{$key}}), "\n"; } =Prints Input Data parsed into 3 columns: Data: ULTRIX CW18.72.0.3 IP-HOST1.log Data: DEC_DECSTATION CW180.72.0.3 IP_HOST_AL.log Data: DEC_DECSTATION_ADDR CW180.72.0.3 IP_HOST_al2.log Data: FOR_VISITORS23_HOST HL617.253.1101.2 IP_HOST_hostinfo. +log Data: FOR_VISITORS24_HOST HL617.253.1101.2 IP_HOST_hostinfo2 +.log Data: FOR_VISITORS25_HOST HL617.253.1101.2 IP_HOST_webform3. +log Dumping each hash key's value(s): HL617.253.1101.2 =>FOR_VISITORS23_HOST, FOR_VISITORS24_HOST, FOR_VISIT +ORS25_HOST CW180.72.0.3 =>DEC_DECSTATION, DEC_DECSTATION_ADDR CW18.72.0.3 =>ULTRIX =cut __DATA__ ULTRIX.CW18.72.0.3.IP-HOST1.log DEC_DECSTATION.CW180.72.0.3.IP_HOST_AL.log DEC_DECSTATION_ADDR.CW180.72.0.3.IP_HOST_al2.log FOR_VISITORS23_HOST.HL617.253.1101.2.IP_HOST_hostinfo.log FOR_VISITORS24_HOST.HL617.253.1101.2.IP_HOST_hostinfo2.log FOR_VISITORS25_HOST.HL617.253.1101.2.IP_HOST_webform3.log
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Storing the log file name as key/value in hash
by Magnolia25 (Sexton) on Jun 07, 2017 at 03:43 UTC | |
by huck (Prior) on Jun 07, 2017 at 04:09 UTC | |
by Marshall (Canon) on Jun 07, 2017 at 07:10 UTC |