You've told XML::Simple to "ForceArray" (i.e. to always create arrays, even if there is only one element).  Thing is that ForceArray expects a boolean value, so as you have ForceArray => 'srw_dc:dc', you've enabled the feature globally (not only for 'srw_dc:dc' as the idea might have been...)

That means you have to access the resulting data structure accordingly, i.e. explicitly specify all array indices

my $records_data = $ref->{'records'}->[0]->{'record'}->... # or shorter my $records_data = $ref->{'records'}[0]{'record'}...

(note the [0] in between the fields 'records' and 'record')

Update: the thing with the "Pseudo-hashes are deprecated" is as follows: in short, as pseudo-hash is an array with a hash in its first element (index 0) that is being used to lookup the array indices to be used for the individual pseudo-hash fields (this applies to Perl versions < 5.10 only, btw).  E.g.

$pseudohash = [ { key => 5 } ];

When you, for example, write

$pseudohash->{key} = 42;

the resulting data structure would look like

$VAR1 = [ { 'key' => 5 }, undef, undef, undef, undef, 42 ];

Two things to note: (1) the pseudo-hash field 'key' maps to array index 5, and (2) the array is automatically resized (as usual, with all indices less than 5 being created as undef).

Now, XML::Simple (with ForceArray enabled) produces a data structure something like this

my $data = { 'records' => [ { 'record' => [ { 'recordPosition' => [ '1' ], }, ], }, ], };

so when you write

my $records_data = $ref->{'records'}->{'record'}->{'recordData'}

the hash that holds 'record' is being used as pseudo-hash indexing array (as it is at index 0 of the 'records' => [...] array/pseudo-hash). And due to what I would call a bug in Perl, using the arrayref as the pseudo-hash-mapped index, doesn't produce an error message, but rather is interpreted as a (typically huge) number, which in turn leads to Perl auto-resizing the array (in this case because of autovivification) until it runs out of memory in your case...


In reply to Re^3: Show error "Out of Mermory"!! by almut
in thread Show error "Out of Mermory"!! by Sachin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.