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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dimensional arrays 1

Status
Not open for further replies.

arcnon

Programmer
Aug 12, 2003
242
0
0
US
I can set a scalar like so

$tile = $data[4][4];

but not this way it returns undef
$tile = $dungeon[$vert][$horz];

so whats wrong
 
Are you sure data exists at the place you are trying to get it from? If the spot you are retrieving is undefined you'll get undef.

Syntactically its correct though.

Use Data::Dumper to view your array in an easy to debug manner.
 
yes I can print it off so I know it is NOT empty. Its a 16 x 18 data set.

How it is generated.
read a file to a array
split each line into characters
push that array into a new arrray

print it out with 2 loops:
1 for vertical elements
1 for horizontal elements

or
print ">$dataset[4][4]<"; # output: '> <' a single space

$tile = $dataset[4][4];

if ($tile eq ' '){} #error undef
 
Are you also certains that $horiz and $vert are properly populated?

Your accessing dead space in the array. Either it wasn't allocated or your logic is telling perl to look outside the allocated range.

 
Do you use the -w option and strict? It is probably a typo somewhere...
 
positive that it is popilated because it prints
and like I said before if I print the spot I am looking for and then try to set it to a $tile it is then undef.
on a test for what it is set to

yes to -w
no use strict

but I'll give it a shot
 
ok I used strict and my'd a few more things and now it works without changing anything.

Whats up with that? ...just seems strange

thanks uid
 
I didn't change a thing I my'd 8 things
 
If using 'my' on some of the variables fixed it, you probably had a locality problem. Were $horz and $vert populated somewhere else in the script before you tried to use them?

Without seeing the whole script, my guess would be that something somewhere else was changing the values of $horz and $vert before you used them but after you thought you'd set them.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top