Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compensating or (inadvertant) period in hash element name.

Status
Not open for further replies.

Numbski

MIS
Mar 27, 2001
56
0
0
US
Okay, take this code as an example:

Code:
Where game_info is a hash

#!/usr/bin/perl -w
use strict;
use warnings;
$game='pacman';
$rom_name='fdjkl23jkl'
$rom_key='size';
$rom_val='1024';

$game_info{$game}{rom}{$rom_name}{$rom_key}=$rom_val;

print "$game_info{$game}{rom}{$rom_name}{$rom_key}\n";

Presuming I haven't typo'd, that should return 1024 and a newline.

Now, let's change to $rom_name='23did.345'

If I attempt to print that line I'll get this error:

Use of uninitialized value in concatenation (.) at ./audit.pl line <line number>.

Now, if instead I do:

Code:
print &quot;$game_info{$game}{rom}{'23did.345'}{$rom_key}\n&quot;;

I get the proper return.

How do you compensate for this? Obviously it's okay to have the period in the variable name, but I have no idea as to how to specify that...?
 
I'm having no problems running the code you posted. Which line is the error/warning referring to?
(and your typo: missing a ; at the end of the $rom_name='' line :)) ----------------------------------------------------------------------------------
...but I'm just a C man trying to see the light
 
I have no such problem, using perl 5.6.1. Not being able to reproduce it, I'm only guessing by saying that it might help not to use variable interpolation in your print. Instead, you would say:
[tt]print $game_info{$game}{rom}{$rom_name}{$rom_key} . &quot;\n&quot;;[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top