Sponsored Content
Full Discussion: Perl hash definition problem
Top Forums Shell Programming and Scripting Perl hash definition problem Post 302405981 by hojung-yoon on Sunday 21st of March 2010 07:31:53 AM
Old 03-21-2010
Bug

I hope this code helps you.

Code:
#!/usr/bin/perl
use warnings;
use strict;

my %programs;

while (my $line = <DATA>) {
    chomp $line;
    my( $company, $site, $program, $product, $price) = split('--', $line);
    push @{ $programs{$program}{$product} }, $price;
}

for my $program (keys %programs) {
    print "$program\n";
    print "list of products: ", join(", ", keys %{$programs{$program}}), "\n";
    print "list of prices: ",
          join(", ", map { @{$programs{$program}{$_}} } keys %{$programs{$program}}), "\n";
}

__DATA__
COMPANY1--SITE1--PROGRAM1--PRODUCT1--PRICE1
COMPANY1--SITE1--PROGRAM2--PRODUCT1--PRICE1
COMPANY1--SITE1--PROGRAM1--PRODUCT2--PRICE3
COMPANY2--SITE1--PROGRAM1--PRODUCT1--PRICE2

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl Hash

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

2. Shell Programming and Scripting

PERL, push to hash of array problem

$key = "a"; $value = "hello"; %myhash = {} ; push @{ myHash{$key} }, $hello; print $myHash{$key}."\n"; this script prints "hello" but has following error message. Reference found where even-sized list expected at ./test line 5. can any one help me to fix this problem?? (3 Replies)
Discussion started by: bonosungho
3 Replies

3. Shell Programming and Scripting

perl using hash

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

4. Shell Programming and Scripting

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. (3 Replies)
Discussion started by: pritish.sas
3 Replies

5. Shell Programming and Scripting

perl hash

Hi i am reading one file and creating Hash from the contents of it my issue is there are 3 different files in 3 different locations having same structure so for parsing these files i have one subroutine which returns hash after reading all the 3 files i need to create consolidated hash from three... (2 Replies)
Discussion started by: zedex
2 Replies

6. Shell Programming and Scripting

Perl Hash:Can not keep hash data in the same order that it was inserted

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

perl hash - using a range as a hash key.

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

Perl hash help

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

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 . my %result ( $abc => { 'data_count' => '10', 'ID' => 'ABC122', } $def => { 'data_count' => '20', 'ID' => 'defASe', ... (1 Reply)
Discussion started by: asak
1 Replies

10. Programming

Perl: restrict perl from automaticaly creating a hash branches on check

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
SYNCE-REMOVE-PROGRAM(1) 				   http://synce.sourceforge.net/				   SYNCE-REMOVE-PROGRAM(1)

NAME
synce-remove-program - removes a program from your device SYNOPSIS
synce-remove-program [-d LEVEL] [-p device_path] [-o UNLOAD_OPT] NAME ... DESCRIPTION
synce-remove-program removes a program on a device connected through SynCE. OPTIONS
-d LEVEL Set debug log level: 0 - No logging (default) 1 - Errors only 2 - Errors and warnings 3 - Everything -p PATH Path to device -h Display help message. -o UNLOAD_OPT Flags to pass to unload.exe on the remote device. Currently no flags are known, but this flag is here in case we find some. NAME The name of the program on the device. Program names are in the form "Provider Program". This is the same way the name will appear under Settings -> Remove programs on your device, or in the ouput from synce-list-programs. AUTHOR
David Eriksson <twogood@users.sourceforge.net>. SEE ALSO
synce(1) synce-list-programs(1) synce-install-cab(1) prun(1) The SynCE project November 2002 SYNCE-REMOVE-PROGRAM(1)
All times are GMT -4. The time now is 10:07 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy