Re: help with array within another array



On 2/27/07, Ravi Malghan <rmalghan@xxxxxxxxx> wrote:
what am I doing wrong here when trying to access the
value john for node1
=========
$SESSION{FirstRun} = 1;
%nodeowner = ("node1", "john", "node2", "nancy");
push(@SESSION, %nodeowner);

print "node1: $SESSION{$nodeowner{node1}}\n";
snip

Off that bat I would say there are several issues with this code:
* you are using uppercase characters for variable names, convention
says only bareword file handles should be all uppercase
* you have an array and a hash named SESSION (which is confusing)
* you don't appear to be using the strict module ("use strict" at the
top of the code)
* you are creating a useless intermediate variable (%nodeowner)
* you are trying to get data out of the hash %SESSION that you put in
the array @SESSION.

Without more context I would rewrite your code like this:

#!/usr/bin/perl
use strict;

my %session;

$session{FirstRun} = 1;
$session{node1} = 'john';
$session{node2} = 'nancy';

print "node1: $session{node1}\n";
.



Relevant Pages

  • Re: CGI::Session
    ... Alexandre Jaquet wrote: ... > use strict; ... > use CGI; ... my $session = new CGI::Session( ...
    (comp.lang.perl.misc)
  • Re: CGI::Session with MySQL Driver
    ... Mark Clements a écrit: ... I want to store user_name in session table ... as an ARRAY ref while "strict ... the string b7f26a2095fb2ff4e11e8ae1295d767e represent the sessionid ...
    (comp.lang.perl.misc)