SPUG: VEXED "Barbarian needs food badly" Scalar inside Hash problem
Jay Gray
jaygray at scn.org
Thu Dec 19 14:30:14 CST 2002
Jonathan,
It works for me. You may see condensed code + output after my sig.
I suggest two things:
1. try
print "MN: '$machine_name'\n";
to see if this is a trailing white-space issue...
2. If that doesn't work, reply to me only && we can bash
the bug && post the final bug fix back to spug-list
-- Jay Gray
package main;
use Data::Dumper;
$self->{WHOAMI}{MACHINE_NAME} = "SP2007";
$self->{MACHINES}{SP2007}{HOURS_TO_RUN} = 42;
$self->{MACHINES}{SP2007}{ENV_VARIABLES} = "foo bar bash";
SetupEnvVariables($self);
exit;
sub SetupEnvVariables
{
my ($self) = @_;
my ($machine_name, $env_value);
#MAKE ANY CHANGES TO THE ENVIRONMENTAL VARIABLES
$machine_name = $self->{WHOAMI}{MACHINE_NAME};
print "MN: $machine_name\n"; # prints SP2007 which is correct
print Data::Dumper->Dump([ $self->{MACHINES} ],
[qw($self->{MACHINES})]);
print "Hours: $self->{MACHINES}{$machine_name}{HOURS_TO_RUN}\n";
# works for me (Jay)
if (exists $self->{MACHINES}{$machine_name}{ENV_VARIABLES})
{ print "Env vars: found\n" }
else { print "Env vars: NOT FOUND!\n"; }
return;
}
#
# OUTPUT
#
MN: SP2007
$self->{MACHINES} = {
'SP2007' => {
'ENV_VARIABLES' => 'foo bar bash',
'HOURS_TO_RUN' => 42
}
};
Hours: 42
Env vars: found
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
For daily traffic, use spug-list for LIST ; for weekly, spug-list-digest
Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org
More information about the spug-list
mailing list