Compare values of hashes of hash for n number of hash in perl without sorting.
Hi,
I have an hashes of hash, where hash is dynamic, it can be n number of hash. i need to compare data_count values of all .
I need to compare the data_count of each hashes of hash, i need to get greater data_count and ID and also lesser( minimum ) data_count and ID.
how to compare the hash values without sorting using perl.
I have a script with dynamic hash of hashes , and I want to print the entire hash (with all other hashes).
Itried to do it recursively by checking if the current key is a hash and if yes call the current function again with refference to the sub hash.
Most of the printing seems to be OK but in... (1 Reply)
hi there, I have some database output that looks like this
SELECT nic_name,nic_duplex,nic_speed,nic_ip FROM network_table WHERE hostname = "server1"
result is this (ive delimited with a pipe for ease of reading)
bge0|full|1000|10.32.100.1
bge1|full|1000|11.12.101.7 ... (1 Reply)
Hi there
I have a hash of hashes made up of the following data
bge0|100|half|10.36.100.21
bge1|1000|full|10.36.100.22
bge2|1000|full|10.36.100.23
which when i turn into a hash, would look like this inside the system
bge0 ->
nic_speed -> 100
nic_duplex -> half
... (6 Replies)
Hi, sorry, two hash related questions in one day .. but this has got me a bit stuck.
I have a mysql database table that kind of looks like this, the table is called "view1" and a snippet of that table (SELECT'ing just rows with serial number 0629AN1200) is below
serial nic_name ... (2 Replies)
Can Someone explain me why even using Tie::IxHash I can not get the output data in the same order that it was inserted? See code below.
#!/usr/bin/perl
use warnings;
use Tie::IxHash;
use strict;
tie (my %programs, "Tie::IxHash");
while (my $line = <DATA>) {
chomp $line;
my(... (1 Reply)
hi all,
i have a small problem regarding sorting the keys in a hash.
my %hash;
for($i=0;$i<19;$i++)
{
$hash{$i}=$i;
}
foreach $c (sort keys %hash)
{
print "\n $hash{$c}";
} (1 Reply)
Hi there, I am trying to dereference my hash of hashes but post dereferencing, it seems to lose its structure I am using Data::dumper to help me anaylise.
This is the code im using to build the HoH, (data comes from a file). I have also performed a Dumper on the data structure before and after... (1 Reply)
Hi Folks
I am very much a newbie at perl but picking it up and I'm hoping you can help.
I have a file input that details all the /etc/group files in our enterprise in the following format: "<host>:<group>:<gid>:<users>"
I want to parse this data display it as the following:... (9 Replies)
I want to sort values of a hash in ascending order.
my %records;
for my $value (sort values %records){print $value,"\n";}
When I use the above code I get values in this order: 1,10,11,2,3,4,5,6,7,8,9. But, I need values in my output in this order: 1,2,3,4,5,6,7,8,9,10,11.
Can Someone... (1 Reply)
Hello experts. I'm having problems with a snippet of code.
I was hoping to get help/advice to correct.
A file that this script parses has changed to the point where
I can no longer use a scalar, it looks as though I need to
create an array for a hash of hashes below.
The first output of... (1 Reply)
Discussion started by: timj123
1 Replies
LEARN ABOUT DEBIAN
hash::withdefaults
Hash::WithDefaults(3pm) User Contributed Perl Documentation Hash::WithDefaults(3pm)NAME
Hash::WithDefaults - class for hashes with key-casing requirements supporting defaults
version 0.05
SYNOPSIS
use Hash::WithDefaults;
%main = ( ... );
tie %h1, 'Hash::WithDefaults', {...};
tied(%h1)->AddDefault(\%main);
tie %h2, 'Hash::WithDefaults', [...];
tied(%h2)->AddDefault(\%main);
# now if you use $h1{$key}, the value is looked up first
# in %h1, then in %main.
DESCRIPTION
This module implements hashes that support "defaults". That is you may specify several more hashes in which the data will be looked up in
case it is not found in the current hash.
Object creation
tie %hash, 'Hash::WithDefault', [$case_option], [\%values];
tie %hash, 'Hash::WithDefault', [$case_option], [@values];
tie %hash, 'Hash::WithDefault', [$case_option], [%values];
The optional $case_option may be one of these values:
Sensitive - the hash will be case sensitive
Tolower - the hash will be case sensitive, all keys are made lowercase
Toupper - the hash will be case sensitive, all keys are made uppercase
Preserve - the hash will be case insensitive, the case is preserved
Lower - the hash will be case insensitive, all keys are made lowercase
Upper - the hash will be case insensitive, all keys are made uppercase
If you pass a hash or array reference or an even list of keys and values to the tie() function, those keys and values will be COPIED to the
resulting magical hash!
After you tie() the hash, you use it just like any other hash.
Functions
AddDefault
tied(%hash)->AddDefault(\%defaults);
This instructs the object to include the %defaults in the search for values. After this the value will be looked up first in %hash itself
and then in %defaults.
You may keep modifying the %defaults and your changes WILL be visible through %hash!
You may add as many defaults to one Hash::WithDefaults object as you like, they will be searched in the order you add them.
If you delete a key from the tied hash, it's only deleted from the list of specific keys, the defaults are never modified through the tied
hash. This means that you may get a default value for a key after you deletethe key from the tied hash!
GetDefaults
$defaults = tied(%hash)->GetDefaults();
push @$defaults, \%another_default;
Returns a reference to the array that stores the defaults. You may delete or insert hash references into the array, but make sure you
NEVER EVER insert anything else than a hash reference into the array!
Config::IniHash example
use Config::IniHash;
$config = ReadIni $inifile, withdefaults => 1, case => 'preserve';
if (exists $config->{':default'}) {
my $default = $config->{':default'};
foreach my $section (keys %$config) {
next if $section =~ /^:/;
tied(%{$config->{$section}})->AddDefault($default)
}
}
And now all normal sections will get the default values from [:default] section ;-)
AUTHOR
Jan Krynicky <Jenda@Krynicky.cz> http://Jenda.Krynicky.cz
COPYRIGHT
Copyright (c) 2002-2009 Jan Krynicky <Jenda@Krynicky.cz>. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
perl v5.14.2 2012-05-26 Hash::WithDefaults(3pm)