Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Is is possible to read in XML file with out use any module?

by depthFirst
on May 12, 2012 at 07:47 UTC ( #970146=perlquestion: print w/ replies, xml ) Need Help??
depthFirst has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, I always use XMLin to read xml file, now I have been asked to read a xml file without any library except build in functions, I suddenly lost...Is this even possible? Thanks for any help!

Comment on Is is possible to read in XML file with out use any module?
Download Code
Re: Is is possible to read in XML file with out use any module?
by Anonymous Monk on May 12, 2012 at 08:10 UTC
Re: Is is possible to read in XML file with out use any module?
by tobyink (Prior) on May 12, 2012 at 11:00 UTC

    It's easy enough to read it in. This will slurp it in as a big string:

    my $xml_text = do { local(@ARGV, $/) = 'myfile.xml'; <> };

    But actually using the content is a different matter. XML is pretty complex to parse, which is why people generally use a pre-written XML module. Parsing a limited subset of XML is generally doable using regular expressions, but I'd still consider this a last resort.

    Any particular reason why you're not using modules? See Top Seven (Bad) Reasons Not To Use Modules.

    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

      hey thanks, I have tried the way you provided to read the .xml file. When I print out the "$xml_text" it seems it is only part of the xml file

      Before I post a question here. I have tried use a while loop

      while(<STDIN>){ print $_; }
      which produce the same output with your method. If I put the xml file to a .txt file. It reads in just fine. the reason I cannot use module is because it is an home work requirement

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (11)
As of 2013-05-22 04:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best material for plates (tableware) is:









    Results (453 votes), past polls