Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Odd

by wog (Curate)
on Feb 23, 2002 at 01:51 UTC ( #147019=note: print w/ replies, xml ) Need Help??


in reply to Odd: Out of memory! error

Your code uses something called pseudo-hashes. Quoth perlref (bleedperl):

[stuff about this being an experimental feature, and the user-visible implementation of pseudohashes begin deprecated in perl 5.8 and slated to go away in perl 5.10.]

Beginning with release 5.005 of Perl, you may use an array reference in some contexts that would normally require a hash reference. This allows you to access array elements using symbolic names, as if they were fields in a struc ture.

For this to work, the array must contain extra informa tion. The first element of the array has to be a hash reference that maps field names to array indices. Here is an example:

$struct = [{foo => 1, bar => 2}, "FOO", "BAR"];
[more code snipped]

You've declared a pseudohash with one element, "c", which is located at the location that {} turns into when it is used as a number. {} is a reference, and when used as a number turns into it's memory location (so it can be compared, mainly). It's memory location is likely to be a very high number. When you access $record->{c}, perl tries to access the array element in @$record at the index specified by that memory location. Since that array element doesn't exist perl tries to expand the array, and fails saying it doesn't have enough memory. (Since arrays can't be stored with holes in perl.)


Comment on Re: Odd
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2014-12-22 11:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (116 votes), past polls