in reply to Storing the log file name as key/value in hash

#!/usr/bin/perl # http://perlmonks.org/?node_id=1191400 use strict; use warnings; my @array = qw( 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 ); my %hash1; /^(.+?)\.(.+?)\.IP/ and push $hash1{$2}->@*, $1 for @array; use Data::Dumper; print Dumper \%hash1;

Replies are listed 'Best First'.
Re^2: Storing the log file name as key/value in hash
by Magnolia25 (Sexton) on May 28, 2017 at 07:15 UTC
    Thank you. Sorry, i didn't get how this has to be compared to my array

     /^(.+?)\.(.+?)\.IP/ and push $hash1{$2}->@*, $1 for @array;

    This gives me Syntax error.

      Try this, or use a more recent version of Perl.

      /^(.+?)\.(.+?)\.IP/ and push @{$hash1{$2}}, $1 for @array;
        Thank you so much. One last thing please need to write the output to a file as

        keyValue : <comma separted values>

        Thanks once again for your time.

      This is an older syntax style that does the same

      /^(.+?)\.(.+?)\.IP/ and push @{$hash1{$2}}, $1 for @array;

        Thank you so much. One last thing please need to write the output to a file as

        keyValue : <comma separted values>

        possibly file name with each key and value Thanks once again for your time.