Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Parse Question

by catfish1116 (Beadle)
on Dec 10, 2019 at 16:48 UTC ( [id://11109932]=perlquestion: print w/replies, xml ) Need Help??

catfish1116 has asked for the wisdom of the Perl Monks concerning the following question:

I got a parsing script to work on a regular file. Now, when I try to use with an XML file to doesn't work, (no ouput). I even tried a regular print statement after creating the array, (\n\n\ELEPHANTS), Below is the code.

my $line = <>; print "This is what line looks like $line \n"; while (defined($line = <>)) { #chomp($line); print "This is what line looks like $line \n"; my @items = (split /N/, $line); #printf "\n\n\nCustomer Name: %-24s \n", $items[31], $items[32], [ +33]; print "\n\n\n.ELEPHANTS\n"; }

TIA The Catfish

Replies are listed 'Best First'.
Re: Parse Question
by Corion (Patriarch) on Dec 10, 2019 at 16:59 UTC

    What does your line look like? Maybe your XML file only has a single line? You discard the first line and do not do anything with it?

    Are you sure you want to split your input on the letter N?

      In my first print statement, I just wanted to see if the message was read in. Basically it is just one record from an XML file, as the entire XML file would be too big to test this simple code. Initially, I was splitting the message on the '>', but that didn't work, so I used N to see if that would change anything. Since my second print statement wasn't working, I commented it out, and just tried to throw another print statement at the end to see if it would execute, (it didn't). Any thoughts ?

        My first thought is to look at your input file. What does it look like? Are you sure that you opened the right file?

        If your print statement doesn't work, maybe you are not reading in the correct file from your code?

        How are you calling your program?

Re: Parse Question
by hippo (Archbishop) on Dec 10, 2019 at 19:06 UTC

      The code worked great for me as well … until I used a file that consisted of an XML message :(

        Still works fine for me even with XML input:

        $ cat base.xml <?xml version="1.0" encoding="UTF-8"?> <root> <foo>bar</foo> </root> $ perl 11109932.pl < base.xml This is what line looks like <?xml version="1.0" encoding="UTF-8"?> This is what line looks like <root> .ELEPHANTS This is what line looks like <foo>bar</foo> .ELEPHANTS This is what line looks like </root> .ELEPHANTS $

        Your steadfast reluctance to provide an SSCCE is doing you no favours.

        ... I used a file ...

        What file?!? Throw us a frickin' bone here!


        Give a man a fish:  <%-{-{-{-<

Re: Parse Question
by karlgoethebier (Abbot) on Dec 10, 2019 at 19:17 UTC

    Reading XML files by line is probably not a good idea. You may consider to use XML::LibXML::Simple or one of the more advanced modules for XML processing. Regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

    perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11109932]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2026-01-18 17:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (122 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.