11-10-2011
Your dereferencing works just fine. The "problem" is how Perl thinks about hashes: a hash is basically an even sized array, with the first element being the key, and the second the associated value. Data:
umper gets that data, and interprets it as an array, for which it dumps the individual elements: first the key, then the value, first a scalar, then a hash reference.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
This is driving me mad, where am I going wrong?
The relevant segment of code:
sub getndsybcons {
my @servers=@{$_};
my @sybservers=@{$_};
my %results;
foreach my $server(@servers) {
my $biggestsyb;
my $biggestsybval=0;
... (9 Replies)
Discussion started by: Smiling Dragon
9 Replies
2. Shell Programming and Scripting
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)
Discussion started by: Alalush
1 Replies
3. Shell Programming and Scripting
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)
Discussion started by: hcclnoodles
1 Replies
4. Shell Programming and Scripting
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)
Discussion started by: hcclnoodles
6 Replies
5. Shell Programming and Scripting
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)
Discussion started by: hcclnoodles
2 Replies
6. Shell Programming and Scripting
Hi,
i want to print the mail exchange servers for a domain using the code below, the problem is that i just get the memory locations (?) of the elements in the output, instead of the mx servers.
I really tried to find a solution, but i guess that i just don't get it (objects, OOP etc).. :)
... (2 Replies)
Discussion started by: mjoh
2 Replies
7. Shell Programming and Scripting
Hi,
This should be a simple one.
All I am doing is adding an email address to my email.
Example abc@xyz.com
I understand that the @ means arrays in PERL. So, I coded the backtick (`) to dereference it. But now I get abc`@`xyz.com
Your help is appreciated.
Thanks
Nurani (2 Replies)
Discussion started by: nurani
2 Replies
8. Shell Programming and Scripting
#use perl 5.8.5;
my %h1=(a=>'b', c=>'d');
my %h2=(a1=>'b1', c1=>'d1');
my $R1=\%h1;
my $R2=\%h2;
my %h= {$R1, $R2};
my $href=\%h; # hash of hashes
foreach my $key (keys %$href){
print "Z::$$href{$key}\n"
}
When I am trying to print elements of hash of hashes,
it prints HASH... (1 Reply)
Discussion started by: shristi
1 Replies
9. Shell Programming and Scripting
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 .
my %result (
$abc => {
'data_count' => '10',
'ID' => 'ABC122',
}
$def => {
'data_count' => '20',
'ID' => 'defASe',
... (1 Reply)
Discussion started by: asak
1 Replies
10. Shell Programming and Scripting
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 REDHAT
hash::util
Hash::Util(3pm) Perl Programmers Reference Guide Hash::Util(3pm)
NAME
Hash::Util - A selection of general-utility hash subroutines
SYNOPSIS
use Hash::Util qw(lock_keys unlock_keys
lock_value unlock_value
lock_hash unlock_hash);
%hash = (foo => 42, bar => 23);
lock_keys(%hash);
lock_keys(%hash, @keyset);
unlock_keys(%hash);
lock_value (%hash, 'foo');
unlock_value(%hash, 'foo');
lock_hash (%hash);
unlock_hash(%hash);
DESCRIPTION
"Hash::Util" contains special functions for manipulating hashes that don't really warrant a keyword.
By default "Hash::Util" does not export anything.
Restricted hashes
5.8.0 introduces the ability to restrict a hash to a certain set of keys. No keys outside of this set can be added. It also introduces
the ability to lock an individual key so it cannot be deleted and the value cannot be changed.
This is intended to largely replace the deprecated pseudo-hashes.
lock_keys
unlock_keys
lock_keys(%hash);
lock_keys(%hash, @keys);
Restricts the given %hash's set of keys to @keys. If @keys is not given it restricts it to its current keyset. No more keys can be
added. delete() and exists() will still work, but will not alter the set of allowed keys. Note: the current implementation prevents the
hash from being bless()ed while it is in a locked state. Any attempt to do so will raise an exception. Of course you can still bless()
the hash before you call lock_keys() so this shouldn't be a problem.
unlock_keys(%hash);
Removes the restriction on the %hash's keyset.
lock_value
unlock_value
lock_value (%hash, $key);
unlock_value(%hash, $key);
Locks and unlocks an individual key of a hash. The value of a locked key cannot be changed.
%hash must have already been locked for this to have useful effect.
lock_hash
unlock_hash
lock_hash(%hash);
lock_hash() locks an entire hash, making all keys and values readonly. No value can be changed, no keys can be added or deleted.
unlock_hash(%hash);
unlock_hash() does the opposite of lock_hash(). All keys and values are made read/write. All values can be changed and keys can be
added and deleted.
AUTHOR
Michael G Schwern <schwern@pobox.com> on top of code by Nick Ing-Simmons and Jeffrey Friedl.
SEE ALSO
Scalar::Util, List::Util, Hash::Util
perl v5.8.0 2002-06-01 Hash::Util(3pm)