in reply to Re: Show error "Out of Mermory"!!
in thread Show error "Out of Mermory"!!

Hi biohisham, Thanks for reply i also done by saving xml in file but the problem("OUT OF MEMORY") didn't solve. So please tell any other way to solve out it. Could u tell me what's "Pseudo-hashes are deprecated" and how to solve it. I am new to perl so that have so many problem.

use Data::Dumper; use XML::Simple; use WWW::Mechanize; my $login_url = "http://www.jstor.org/action/doXmlSearch?query=dc.titl +e+%3D+%22test%22&version=1.1&operation=searchRetrieve&recordSchema=in +fo%3Asrw%2Fschema%2F1%2Fdc-v1.1&maximumRecords=10&startRecord=1&a.dis +cipline=&recordPacking=xml"; my $mech = new WWW::Mechanize; $mech->get($login_url); my $xml = $mech->content; open (OUT, "> jestor_1.xml") || \ &htmlDie ("Error: Could not open output file!\n"); my @contents = split '\n', $xml; my $line; foreach $line (@contents) { chomp($line); next if ( $line =~ /^\s*$/m ); print OUT "$line\n"; } close (OUT); my $xs = XML::Simple->new(ForceArray => 'srw_dc:dc'); my $ref = $xs->XMLin("jestor_1.xml"); my $records_data = $ref->{'records'}->{'record'}->{'recordData'}->{'sr +w_dc:dc'}; foreach my $rd ($records_data){ my ($title) = $rd->{'dc:title'}; print "\n " . $title; }

Replies are listed 'Best First'.
Re^3: Show error "Out of Mermory"!!
by almut (Canon) on Oct 12, 2009 at 12:41 UTC

    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...

Re^3: Show error "Out of Mermory"!!
by biohisham (Priest) on Oct 12, 2009 at 11:02 UTC

    Saving to a file might not solve the problem, you haven't said whether you disabled buffering or not, you haven't shown that either. In Perl you got line-buffering and block-buffering, saving to files employs block buffering since print and write operations are involved hence sometimes you need to enforce a buffer flush every time a filehandle is written to in case you are afraid that memory issues would come-up.

    print OUT "$line\n"; autoflush OUT 1;
    This link can be useful for you to learn more about buffering and for pseudo hashes, a quick googling around the place can give you an indication; Pseudo-hashes deprecated, pseudo hashes.. Perl is a lovable language, just be committed to it and do what it takes to get there.

    Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind.

      Hi, i use

      print OUT "$line\n"; autoflush OUT 1;

      but it's showing "out of memory!!" message again. Following my jestor_1.xml file. Now i wants to print title from this file. so what i do??

      <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="/templates/xsl/_jstor/search/se +archRetrieveResponse.xsl"?><searchRetrieveResponse xmlns="http://www. +loc.gov/zing/srw/"> <version>1.1</version> <numberOfRecords>10588</numberOfRecords> <records> <record> <recordSchema>info:srw/schema/1/dc-v1.1</recordSchema> <recordPacking>xml</recordPacking> <recordData> <srw_dc:dc xmlns:srw_dc="info:srw/schema/1/dc-v1.1" xmlns:dc="http://purl.org/dc/elements/1.1/"> <dc:identifier>ISSN: 0010096X</dc:identifier> <dc:identifier>URL: http://www.jstor.org/stable/357303< +/dc:identifier> <dc:title>Test</dc:title> <dc:creator>Wm. Leonard</dc:creator> <dc:relation>College Composition and Communication, Vol +. 29, No. 2</dc:relation> <dc:coverage>p. 161</dc:coverage> <dc:rights>Copyright 1978 National Council of Teachers +of English</dc:rights> <dc:publisher>National Council of Teachers of English</ +dc:publisher> <dc:date>1978-05-01</dc:date> <dc:type>FLA</dc:type> <dc:language>eng</dc:language> </srw_dc:dc> </recordData> <recordPosition>1</recordPosition> </record> <record> <recordSchema>info:srw/schema/1/dc-v1.1</recordSchema> <recordPacking>xml</recordPacking> <recordData> <srw_dc:dc xmlns:srw_dc="info:srw/schema/1/dc-v1.1" xmlns:dc="http://purl.org/dc/elements/1.1/"> <dc:identifier>ISSN: 00224103</dc:identifier> <dc:identifier>URL: http://www.jstor.org/stable/4002914 +9</dc:identifier> <dc:title>A Test to Test Test-Wiseness</dc:title> <dc:creator>Berta W. Parrish</dc:creator> <dc:relation>Journal of Reading, Vol. 25, No. 7</dc:rel +ation> <dc:coverage>pp. 672-675</dc:coverage> <dc:rights>Copyright 1982 International Reading Associa +tion</dc:rights> <dc:publisher>International Reading Association</dc:pub +lisher> <dc:date>1982-04-01</dc:date> <dc:type>FLA</dc:type> <dc:language>eng</dc:language> </srw_dc:dc> </recordData> <recordPosition>2</recordPosition> </record> <record> <recordSchema>info:srw/schema/1/dc-v1.1</recordSchema> <recordPacking>xml</recordPacking> <recordData> <srw_dc:dc xmlns:srw_dc="info:srw/schema/1/dc-v1.1" xmlns:dc="http://purl.org/dc/elements/1.1/"> <dc:identifier>ISSN: 00100994</dc:identifier> <dc:identifier>URL: http://www.jstor.org/stable/378106< +/dc:identifier> <dc:title>Test Pattern</dc:title> <dc:creator>Roderick Potter</dc:creator> <dc:relation>College English, Vol. 53, No. 3</dc:relati +on> <dc:coverage>p. 311</dc:coverage> <dc:rights>Copyright 1991 National Council of Teachers +of English</dc:rights> <dc:publisher>National Council of Teachers of English</ +dc:publisher> <dc:date>1991-03-01</dc:date> <dc:type>FLA</dc:type> <dc:language>eng</dc:language> </srw_dc:dc> </recordData> <recordPosition>3</recordPosition> </record> <record> <recordSchema>info:srw/schema/1/dc-v1.1</recordSchema> <recordPacking>xml</recordPacking> <recordData> <srw_dc:dc xmlns:srw_dc="info:srw/schema/1/dc-v1.1" xmlns:dc="http://purl.org/dc/elements/1.1/"> <dc:identifier>ISSN: 0091732X</dc:identifier> <dc:identifier>URL: http://www.jstor.org/stable/1167177 +</dc:identifier> <dc:title>Test Theory</dc:title> <dc:creator>Michael J. Subkoviak</dc:creator> <dc:creator>Frank B. Baker</dc:creator> <dc:relation>Review of Research in Education, Vol. 5</d +c:relation> <dc:coverage>pp. 275-317</dc:coverage> <dc:rights>Copyright 1977 American Educational Research + Association</dc:rights> <dc:publisher>American Educational Research Association +</dc:publisher> <dc:date>1977-01-01</dc:date> <dc:type>FLA</dc:type> <dc:language>eng</dc:language> </srw_dc:dc> </recordData> <recordPosition>4</recordPosition> </record> <record> <recordSchema>info:srw/schema/1/dc-v1.1</recordSchema> <recordPacking>xml</recordPacking> <recordData> <srw_dc:dc xmlns:srw_dc="info:srw/schema/1/dc-v1.1" xmlns:dc="http://purl.org/dc/elements/1.1/"> <dc:identifier>ISSN: 00030554</dc:identifier> <dc:identifier>URL: http://www.jstor.org/stable/1944418 +</dc:identifier> <dc:title>Tuberculin Test</dc:title> <dc:creator>Lorian P. Jefferson</dc:creator> <dc:relation>The American Political Science Review, Vol +. 4, No. 1</dc:relation> <dc:coverage>p. 90</dc:coverage> <dc:rights>Copyright 1910 American Political Science As +sociation</dc:rights> <dc:publisher>American Political Science Association</d +c:publisher> <dc:date>1910-02-01</dc:date> <dc:type>FLA</dc:type> <dc:language>eng</dc:language> </srw_dc:dc> </recordData> <recordPosition>5</recordPosition> </record> <record> <recordSchema>info:srw/schema/1/dc-v1.1</recordSchema> <recordPacking>xml</recordPacking> <recordData> <srw_dc:dc xmlns:srw_dc="info:srw/schema/1/dc-v1.1" xmlns:dc="http://purl.org/dc/elements/1.1/"> <dc:identifier>ISSN: 0002936X</dc:identifier> <dc:identifier>URL: http://www.jstor.org/stable/3410411 +</dc:identifier> <dc:title>Test Meals</dc:title> <dc:creator>E. M. Geraghty</dc:creator> <dc:relation>The American Journal of Nursing, Vol. 32, +No. 3</dc:relation> <dc:coverage>pp. 297-300</dc:coverage> <dc:rights>Copyright 1932 Wolters Kluwer Health, Inc.</ +dc:rights> <dc:publisher>Wolters Kluwer Health, Inc.</dc:publisher +> <dc:date>1932-03-01</dc:date> <dc:type>FLA</dc:type> <dc:language>eng</dc:language> </srw_dc:dc> </recordData> <recordPosition>6</recordPosition> </record> <record> <recordSchema>info:srw/schema/1/dc-v1.1</recordSchema> <recordPacking>xml</recordPacking> <recordData> <srw_dc:dc xmlns:srw_dc="info:srw/schema/1/dc-v1.1" xmlns:dc="http://purl.org/dc/elements/1.1/"> <dc:identifier>ISSN: 0002936X</dc:identifier> <dc:identifier>URL: http://www.jstor.org/stable/3462165 +</dc:identifier> <dc:title>Nonstress Test</dc:title> <dc:creator>Rita Kopf</dc:creator> <dc:relation>The American Journal of Nursing, Vol. 78, +No. 12</dc:relation> <dc:coverage>pp. 2115-2116</dc:coverage> <dc:rights>Copyright 1978 Wolters Kluwer Health, Inc.</ +dc:rights> <dc:publisher>Wolters Kluwer Health, Inc.</dc:publisher +> <dc:date>1978-12-01</dc:date> <dc:type>FLA</dc:type> <dc:language>eng</dc:language> </srw_dc:dc> </recordData> <recordPosition>7</recordPosition> </record> <record> <recordSchema>info:srw/schema/1/dc-v1.1</recordSchema> <recordPacking>xml</recordPacking> <recordData> <srw_dc:dc xmlns:srw_dc="info:srw/schema/1/dc-v1.1" xmlns:dc="http://purl.org/dc/elements/1.1/"> <dc:identifier>ISSN: 00138274</dc:identifier> <dc:identifier>URL: http://www.jstor.org/stable/820690< +/dc:identifier> <dc:title>Mending Test</dc:title> <dc:creator>Penelope Bryant Turk</dc:creator> <dc:relation>The English Journal, Vol. 82, No. 1</dc:re +lation> <dc:coverage>p. 86</dc:coverage> <dc:rights>Copyright 1993 National Council of Teachers +of English</dc:rights> <dc:publisher>National Council of Teachers of English</ +dc:publisher> <dc:date>1993-01-01</dc:date> <dc:type>FLA</dc:type> <dc:language>eng</dc:language> </srw_dc:dc> </recordData> <recordPosition>8</recordPosition> </record> <record> <recordSchema>info:srw/schema/1/dc-v1.1</recordSchema> <recordPacking>xml</recordPacking> <recordData> <srw_dc:dc xmlns:srw_dc="info:srw/schema/1/dc-v1.1" xmlns:dc="http://purl.org/dc/elements/1.1/"> <dc:identifier>ISSN: 00368423</dc:identifier> <dc:identifier>URL: http://www.jstor.org/stable/4014559 +</dc:identifier> <dc:title>Test Flight</dc:title> <dc:creator>Ben Harder</dc:creator> <dc:relation>Science News, Vol. 163, No. 21</dc:relatio +n> <dc:coverage>p. 326</dc:coverage> <dc:rights>Copyright 2003 Society for Science &amp; the + Public</dc:rights> <dc:publisher>Society for Science &amp; the Public</dc: +publisher> <dc:date>2003-05-24</dc:date> <dc:type>FLA</dc:type> <dc:language>eng</dc:language> </srw_dc:dc> </recordData> <recordPosition>9</recordPosition> </record> <record> <recordSchema>info:srw/schema/1/dc-v1.1</recordSchema> <recordPacking>xml</recordPacking> <recordData> <srw_dc:dc xmlns:srw_dc="info:srw/schema/1/dc-v1.1" xmlns:dc="http://purl.org/dc/elements/1.1/"> <dc:identifier>ISSN: 00380431</dc:identifier> <dc:identifier>URL: http://www.jstor.org/stable/2784994 +</dc:identifier> <dc:title>Situation Test</dc:title> <dc:creator>J. L. Moreno</dc:creator> <dc:relation>Sociometry, Vol. 9, No. 2/3</dc:relation> <dc:coverage>pp. 166-167</dc:coverage> <dc:rights>Copyright 1946 American Sociological Associa +tion</dc:rights> <dc:publisher>American Sociological Association</dc:pub +lisher> <dc:date>1946-05-01</dc:date> <dc:type>FLA</dc:type> <dc:language>eng</dc:language> </srw_dc:dc> </recordData> <recordPosition>10</recordPosition> </record> </records> <nextRecordPosition>11</nextRecordPosition> <echoedSearchRetrieveRequest> <version>1.1</version> <query>dc.title = "test"</query> <startRecord>1</startRecord> <maximumRecords>10</maximumRecords> <recordPacking>xml</recordPacking> <recordSchema>info:srw/schema/1/dc-v1.1</recordSchema> </echoedSearchRetrieveRequest> </searchRetrieveResponse>