sfrisch@mt.gov has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to print the keys and the values of a hash of array using a data structure. I would like to it sorted by key.<\p>
I have got the array set up at least I think I do I have all kinds of print statments telling me that I am not too crazy. I would like to have a print out that looks like the following only soted by the second -- or first fields.
Input
DOABIL3020 ITSD-ENT_OP-DMSB-DIDS Ora
DOABIL309 EXE-SOS-3201_DFLT OraDOABIL3400 ITSD-ENT_OP-ETSB-MID PRD
DOABIL5310 ITSD-ENT_OP-ETSB-MID TST
DOABIL6230 EXE-SOS-3201_DFLT PRD
DOABIL7001 ITSD-ENT_OP-ETSB-EAS PRD
DOABIL7005 ITSD-ENT_OP-AIMB-DCSEC PRD
DOABIL7006 ITSD-ENT_OP-AIMB-DCSEC PRD
DOABIL7504 EXE-SOS-3201_DFLT PRD
DOABIL7581 ITSD-ENT_OP-NTSB-NET PRD
DOABIL7582 ITSD-ENT_OP-NTSB-NET PRD
DOABIL7583 ITSD-ENT_OP-NTSB-NET PRD
Out put is the same only sorted that is what I am shooting for.open INTO,">sumfile.txt"; open FILE, "serverinventory.txt"; while(<FILE>){ chomp; $_ =~ s/\"//g; #$_=~ s/\,/ /g; @LINE=split(/\,/); $HOST=$LINE[1]; if($HOST =~/DOAISDBLADE/|| $HOST =~ /DOAISD9/|| $HOST =~/K +VM/|| $HOST =~/DOABILBLA/){ } elsif($LINE[19] =~ /EXE/||$LINE[19] =~ /ITSD/||$LINE[19] = +~/REV/){ $FMM = $LINE[19]; $USE = $LINE[16]; $HOST = $LINE[1]; my $USE = substr($USE,0,3); my $AG = substr($LINE[16],4,17); #printf INTO ("%0s %0s\n",$FMM,$HOST,$USE); print INTO "$HOST $FMM $USE\n"; } } close FILE; close INTO; # MOVe to running against the new file made sumery.txt open FILE2,"sumfile.txt"; open too,">out.txt"; # open file for counts to be depposited to while(<FILE2>){ chomp; @arry1 = split(/ /); $TOTAL = $tab1=$arry1[0]; $tab2=$arry1[1]; #print "$tab1 $tab2\n"; push(@ {$ARG{"$tab1"}},"$tab2"); } # foreach $string (keys %ARG) { #HASH OF ARRAY SORTED $last = $#{$ARG{$string}}; #GETS THE COUNT OF THE JOBS FOR +EACH TABLE $last=$last + 1; print "$string $ARG{$string}\n"; }
I get a print of the keys but not the value. So I do not understand how to get to all tyhe data I am generating.<\p>
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Accessing or printing key and value
by GrandFather (Saint) on Dec 11, 2012 at 01:20 UTC | |
Re: Accessing or printing key and value
by ww (Archbishop) on Dec 11, 2012 at 00:49 UTC | |
Re: Accessing or printing key and value
by frozenwithjoy (Priest) on Dec 11, 2012 at 00:38 UTC | |
Re: Accessing or printing key and value
by 2teez (Vicar) on Dec 11, 2012 at 01:22 UTC |