07-20-2009
perl hash
This is my data
1 0
1 0
1 1
1 2
1 6
1 7
Assume that first field is key and 2nd field is value
I want to create a hash in perl, on this data. My hash should having uniq key and all values by , separated.
1,0,0,1,2,6,7
1 will be my key and rest of are should be values.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi
Help me with some good links of Hash with in Hash .(Multidimensional hash)..
Regards
Harikrishna (1 Reply)
Discussion started by: Harikrishna
1 Replies
2. Shell Programming and Scripting
HI
I have a hash like this
$hashname->{$filesystem}->{'fsname'}=$filesystem;
How to get the values from this multilevel hash.
Thanks in advance... :) (1 Reply)
Discussion started by: Harikrishna
1 Replies
3. Shell Programming and Scripting
hi
i have two hash achi %disk1,%disk2 with( key, value) (key1,value1)
How to store it in another hash..
Plz replyyy.
Regards
Hari (1 Reply)
Discussion started by: Harikrishna
1 Replies
4. Shell Programming and Scripting
i have an hash table in which each value is an array. How can i print for each key the array values??? something like this:
thanks (2 Replies)
Discussion started by: littleboyblu
2 Replies
5. Shell Programming and Scripting
i want to ask is it i can use hash in perl to store a page number with a list of words which is in that page and then print it out?
Example
Page 1 contains a are boy cat ............. (a list of sorted words)
how can i store it in a hash?
Thank you (3 Replies)
Discussion started by: mingming88
3 Replies
6. Shell Programming and Scripting
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)
Discussion started by: jgfcoimbra
1 Replies
7. Shell Programming and Scripting
Hi,
In Perl, is it possible to use a range of numbers with '..' as a key in a hash?
Something in like:
%hash = (
'768..1536' => '1G',
'1537..2560' => '2G'
);
That is, the range operation is evaluated, and all members of the range are... (3 Replies)
Discussion started by: dsw
3 Replies
8. Shell Programming and Scripting
Hi ,
i have the below code its working fine when i execute in unix , but its not working in windows could you pls explain me where i am going wrong.
This is the program
$data = { '1' => 'one' ,
'2' => 'two' ,
3 => 'three'
};
print "hello : $data->{'1'}... (2 Replies)
Discussion started by: ragilla
2 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. Programming
My issue is that the perl script (as I have done it so far) created empty branches when I try to check some branches on existence.
I am using multydimentional hashes: found it as the best way for information that I need to handle. Saing multidimentional I means hash of hashes ... So, I have
... (2 Replies)
Discussion started by: alex_5161
2 Replies
LEARN ABOUT MOJAVE
tie::memoize
Tie::Memoize(3pm) Perl Programmers Reference Guide Tie::Memoize(3pm)
NAME
Tie::Memoize - add data to hash when needed
SYNOPSIS
require Tie::Memoize;
tie %hash, 'Tie::Memoize',
&fetch, # The rest is optional
$DATA, &exists,
{%ini_value}, {%ini_existence};
DESCRIPTION
This package allows a tied hash to autoload its values on the first access, and to use the cached value on the following accesses.
Only read-accesses (via fetching the value or "exists") result in calls to the functions; the modify-accesses are performed as on a normal
hash.
The required arguments during "tie" are the hash, the package, and the reference to the "FETCH"ing function. The optional arguments are an
arbitrary scalar $data, the reference to the "EXISTS" function, and initial values of the hash and of the existence cache.
Both the "FETCH"ing function and the "EXISTS" functions have the same signature: the arguments are "$key, $data"; $data is the same value
as given as argument during tie()ing. Both functions should return an empty list if the value does not exist. If "EXISTS" function is
different from the "FETCH"ing function, it should return a TRUE value on success. The "FETCH"ing function should return the intended value
if the key is valid.
Inheriting from Tie::Memoize
The structure of the tied() data is an array reference with elements
0: cache of known values
1: cache of known existence of keys
2: FETCH function
3: EXISTS function
4: $data
The rest is for internal usage of this package. In particular, if TIEHASH is overwritten, it should call SUPER::TIEHASH.
EXAMPLE
sub slurp {
my ($key, $dir) = shift;
open my $h, '<', "$dir/$key" or return;
local $/; <$h> # slurp it all
}
sub exists { my ($key, $dir) = shift; return -f "$dir/$key" }
tie %hash, 'Tie::Memoize', &slurp, $directory, &exists,
{ fake_file1 => $content1, fake_file2 => $content2 },
{ pretend_does_not_exists => 0, known_to_exist => 1 };
This example treats the slightly modified contents of $directory as a hash. The modifications are that the keys fake_file1 and fake_file2
fetch values $content1 and $content2, and pretend_does_not_exists will never be accessed. Additionally, the existence of known_to_exist is
never checked (so if it does not exists when its content is needed, the user of %hash may be confused).
BUGS
FIRSTKEY and NEXTKEY methods go through the keys which were already read, not all the possible keys of the hash.
AUTHOR
Ilya Zakharevich <mailto:perl-module-hash-memoize@ilyaz.org>.
perl v5.18.2 2013-11-04 Tie::Memoize(3pm)