CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
assign each value of a hash to a variable

 



schnubbex
Novice

Aug 29, 2014, 1:23 PM

Post #1 of 3 (1269 views)
assign each value of a hash to a variable Can't Post

Hello guys,
2 days back you helped me to understand how to read out multiple values of one key. My problem now is, that i want to multiply or devide or do other math stuff with the values but somehow i cant get them into variables.
Error:
Use of uninitialized value $value2 in concatenation (.) or string at D:/Eclipse_perl/UserbinCrash/Userbin/Crash.pl line 21, <$peak_fh> line 43.

when i use this code

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


open ( my $peak_fh, "<", "input1.txt");
my %Data2Hash;
my @ values;

while ( my $line = <$peak_fh> ) {
chomp $line;
next if $line =~ /1337/; #Skip Header
our ($key, @values) = split /\s+/, $line;
push @{$Data2Hash{$key}}, @values;

}
#$" = ', ';
foreach my $key ( keys %Data2Hash )
{
my ($value1,$value2) = $Data2Hash{$key};
print "key is $key value is $value1 value2 is $value2"; # i want to devide value2 with value1 later for example

}

close $peak_fh;

Any ideas?
I used this as help but i dont quite get it
http://www.perlmonks.org/?node_id=1050281


(This post was edited by schnubbex on Aug 29, 2014, 1:31 PM)


FishMonger
Veteran / Moderator

Aug 29, 2014, 1:27 PM

Post #2 of 3 (1266 views)
Re: [schnubbex] essign each value of a hash to a variable [In reply to] Can't Post

Try changing:

Code
my ($value1,$value2) = $Data2Hash{$key};


to:

Code
my ($value1,$value2) = @{ $Data2Hash{$key} };



schnubbex
Novice

Aug 29, 2014, 1:32 PM

Post #3 of 3 (1264 views)
Re: [FishMonger] essign each value of a hash to a variable [In reply to] Can't Post

OMG thank you so mutch!!!!

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives