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!

Replies are listed 'Best First'.
Re: Is is possible to read in XML file with out use any module?
by tobyink (Canon) 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

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