Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: Adding Hash Keys/Values

by kennethk (Monsignor)
on Nov 08, 2012 at 15:57 UTC ( #1002936=note: print w/ replies, xml ) Need Help??

in reply to Adding Hash Keys/Values

The answer to your immediate issue is that you need to use double quotes instead of single quotes if you want a variable value to interpolate into a string. Your line should therefore read $table_hash{"$n,0"} = $m;. See Quote and Quote like Operators in perlop.

You are using compound keys to emulate a multidimensional array in your code, which is very Perl 4. With the addition of array references (a couple decades ago), I would do this with something like:

#!usr/bin/perl use strict; use warnings; use Data::Dumper; my @table = ( ['X', 'Y', 'Z'], ); print Dumper \@table; my $m=0; foreach my $n (0..3) { $table[$n][0] = $m++; }; print Dumper \@table;

See perlreftut.

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Comment on Re: Adding Hash Keys/Values
Select or Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1002936]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (9)
As of 2014-07-28 22:00 GMT
Find Nodes?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:

    Results (210 votes), past polls