hashes

Sorting an Array Reference to Hashes

After executing these lines in Perl: my $data = `curl '$url'`; my $pets = XMLin($data)->(pets); I have an array reference that contains references to hashes: $VAR1 = [ { 'title' => 'cat', 'count' => '210' }, { 'title' => 'dog', 'count' => '210' } ] In Perl, how do I sort the h...

Array of hashes

Hi , In perl , i have an array of hashes like 0 HASH(0x98335e0) 'title' => 1177 'author' => 'ABC' 'quantity' => '-100' 1 HASH(0x832a9f0) 'title' => 1177 'author' => 'ABC' 'quantity' => '100' 2 HASH(0x98335e0) 'title' => 1127 'author' => 'DEF' 'quantity' => '5100' 3 HASH(0x832a9f0) 'title' => 1277 ...

help understanding perl hash

Perl newbie here...I had help with this working perl script with some HASH code and I just need help understanding that code and if it could be written in a way that I would understand the use of HASHES more easily or visually?? In summary the script does a regex to filter on date and the rest of the regex will pull data related to tha...

perl - help passing/looping in arguments from file or within a separate perl data structure

I have a while loop that reads in a single file: my %MyItems = (); while (my $line = <>) { chomp $line; if ($line =~ m/(.* $mon $day) \d{2}:\d{2}:\d{2} $year: ([^:]+):backup:/) { my $BckupDate="$1 $year"; my $BckupSet =$2; $MyItems{$BckupSet}->{'MyLogdate'} = $...

help printing out hash keys to needed format

I need help printing out data from a hash/hash ref to STDOUT or file with data in a specific order if possible. I have a perl routine that uses hash references like so: #!/usr/local/bin/perl use strict; use warnings; use File::Basename; use Data::Dumper; my %MyItems; my $ARGV ="/var/logdir/server1.log"; my $mon = 'Aug'; my $day = '0...

Perl Hashes and array

Hi, I have an array with 28 elements. I copied array contents into a hash. If i try to print the hash it is not showing all keys and values. Code is given below, @new; %hash = @new; foreach $food (keys %hash) { $color = $hash{$food}; print "$food is $color.\n"; } Output is :: attribute is Mandatory. min is 0X00. value is 778....

perl - help with hash and dumping of records

I have a perl script that is only keeping the last set of records for a named set and I have more than one set of records. So its over writing the data in the hash and just keeping the last set. I need help in printing out all the records. Thanks! Here's a copy of my script: #!/usr/local/bin/perl use strict; use warnings; use Data::D...

How do I initialize values in a hash without a loop?

I am trying to figure out a way to initialize a hash without having to go through a loop. I was hoping to use slices for that, but it doesn't seem to produce the expected results. Consider the following code: #!/usr/bin/perl use Data::Dumper; my %hash = (); $hash{currency_symbol} = 'BRL'; $hash{currency_name} = 'Real'; print Dumper(%h...

How would I use a hash slice to initialize a hash stored in a data structure?

In an earlier question I asked how to initialize a Perl hash using slices. It is done like this: my %hash = (); my @fields = ('currency_symbol', 'currency_name'); my @array = ('BRL','Real'); @hash{@fields} = @array; Now let's imagine a more complex hash, and here is how it is initialized: my %hash = (); my $iso = 'BR'; $hash->{$iso}-...

Perl DBI fetchall_hashref

Consider the following table: mysql> select * from vCountryStatus; +-------------+------------+------+---------+--------+-----------------+ | CountryName | CountryISO | Code | Status | Symbol | CurrencyName | +-------------+------------+------+---------+--------+-----------------+ | Brazil | BR | 55 | LIVE | BRL ...

Sending a hash using eventmachine

I want to send a hash populated with data from a EventMachine client to a server. The problem is that the server receive_date method just prints a string. The server: def receive_data(data) send_data("Ready") puts data[:total] end The client: def receive_data(data) send_data( get_memory() ) end def get_memory sigar ...

How can I create arrays and hashes in Perl?

This is not generic question. I have asked this question because I'm confused with creating Perl arrays. How do I create or define the Array or hash? What are other ways to do that? How do I clear a array or hash? What are other ways to do that? How do I create a array or hash with empty element? What are the ways to create hash with...