Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: How to use perl to parsing a XML file to csv file which have the same sequence in xml file?

by Anonymous Monk
on Dec 28, 2012 at 22:25 UTC ( #1010754=note: print w/ replies, xml ) Need Help??


in reply to Re: How to use perl to parsing a XML file to csv file which have the same sequence in xml file?
in thread How to use perl to parsing a XML file to csv file which have the same sequence in xml file?

Hello

I tried to run the example provided here, and I get the following error:

 Expected fields to be an array ref at xml.pl line 11

When I look at the contents of $book, I see:

$VAR1 = bless( [ 'Book 1 author 1', 'Book 1 author 2', 'Book 1 title', 'Book1ISBN' ], 'XML::LibXML::NodeList' ); $VAR1 = bless( [ 'Book 2 author 1', 'Book 2 author 2', 'Book 2 title', 'Book2ISBN' ], 'XML::LibXML::NodeList' );
I am running perl 5.10.1 -- any tips?


Comment on Re^2: How to use perl to parsing a XML file to csv file which have the same sequence in xml file?
Select or Download Code
Re^3: How to use perl to parsing a XML file to csv file which have the same sequence in xml file?
by Anonymous Monk on Dec 28, 2012 at 23:21 UTC

    I am running perl 5.10.1 -- any tips?

    Forget it, its magic :) I get

    PL_linestr not long enough, was Devel::Declare loaded soon enough in f +udge at PerlX/MethodCallWithBlock.pm line 107.

    Report it to PerlX::MethodCallWithBlock maintainer

Re^3: How to use perl to parsing a XML file to csv file which have the same sequence in xml file?
by tobyink (Abbot) on Dec 30, 2012 at 19:38 UTC

    It worked on my machine, but Text::CSV's behaviour can be a little variable - it has two underlying implementations: one in pure Perl, and a faster one in C. Which one you get is the luck of the draw. In this case, $row is a blessed arrayref; Text::CSV expects an arrayref; it looks like one of the implementations rejects the arrayref if it's blessed but the other does not.

    $csv->print(\*STDOUT, [@$row]); # unblessed shallow clone of $row
    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
      Hah, its the PP version that is too picky :)
      $ perl -MText::CSV_PP -e " Text::CSV_PP->new->print(\*STDOUT, [1..3] ) + " 1,2,3 $ perl -MText::CSV_XS -e " Text::CSV_XS->new->print(\*STDOUT, [1..3] ) + " 1,2,3 $ perl -MText::CSV_XS -e " Text::CSV_XS->new->print(\*STDOUT, bless[1. +.3],666 ) " 1,2,3 $ perl -MText::CSV_PP -e " Text::CSV_PP->new->print(\*STDOUT, bless[1. +.3],666 ) " Expected fields to be an array ref at -e line 1.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (12)
As of 2015-07-07 13:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (88 votes), past polls