Slashdot Mirror


XML::Simple for Perl Developers

An anonymous reader writes "XML has become pervasive in the computing world and is buried more and more deeply into modern applications and operating systems. It's imperative for the Perl programmer to develop a good understanding of how to use it. In a surprisingly large number of cases, you only need one tool to integrate XML into a Perl application, XML::Simple. This article tells you where to get it, how to use it, and where to go next."

19 of 186 comments (clear)

  1. XML::LibXML is where it's at by teknomage1 · · Score: 5, Informative

    XML::LibXML is where it's at, it is a) quite a bit faster and b) has a sensible interfce rather than giving you useless empty hashrefs in the middle of a tree.

    --
    Stop intellectual property from infringing on me
    1. Re:XML::LibXML is where it's at by rvalles · · Score: 4, Informative

      I agree completely. I've used both recently (and XML::Xpath) and XML::LibXML is much more powerful and sane, while at the same time it is about as easy to learn. There's the added advantages that being just LibXML bindings what's learned is useful in other programming languages, and that nodes are referred using Xpath, which is a really powerful and useful W3C standard that, again, is worth learning.

  2. Re:Bah, who the hell still uses perl? by ThatDamnMurphyGuy · · Score: 5, Insightful

    No, professionals write good code, regardless of the language. There is just as much shitty Python/Ruby out there as there is Perl.

  3. Re:Who The Hell Still Uses Perl? by BrianRoach · · Score: 5, Insightful

    "Outside of non-professional teenage Slashdot readers who still think the shitty Perl syntax is 'kewl', who the hell cares about the language anymore?"

    I usually don't reply to trolls, but ...

    The answer is hundreds of thousands of people around the world who use the correct tool for a given job, rather then trying to hammer in screws with the "latest and greatest".

    PS, if you're not clueless and actually are a professional software developer, you can write code in perl that is every bit as readable as . It even supports comments!

    - Roach
    (Who writes code in perl, as well as a number of other languages depending on the task at hand.)

  4. Re:Bah, who the hell still uses perl? by soapbox · · Score: 3, Insightful

    fine, I'll feed the troll.

    Parsing perl with wet-ware isn't always easy. Obfuscating your code in the name of optimization should be countered with good commenting. Every useful script will have to be maintained, and the grandparent post is totally correct. I work minor miracles with Perl; or, miracles to me, anyway--I couldn't have created my dissertation data without Fortran--specifically g95--and Perl.

    I know there are lots of useful languages out there. Every language has its fanboys. Heck, I liked the PDP-11 macro language a lot. If people produce useful code with Perl, don't complain about it; be glad for them.

  5. What? by cliveholloway · · Score: 4, Insightful

    This is the most pointless article I've seen linked from slashdot in a long time (and yes, I've seen a lot of crap here). What is the point of posting a run of the mill tutorial on something that's been covered many times before?

    Having spent a lot of time playing with this crap lately, can I just butt into this pointless thread and say screw XML, use YAML or JSON instead. XML is a steaming, clumsy overrated turd. I benchmarked XML::Simple against YAML::Syck - the latter encoded 2.5 times faster and parsed nine times faster than XML::Simple. The syck library is indeed aptly named.

    "Leverage the power of XML" by deprecating it wherever you can for a more sensible cross platform format.

    </rant>

    --
    -- Trinity in high heels carrying a whip: The donimatrix - there is no spoonerism
    1. Re:What? by jtolds · · Score: 5, Funny

      "Leverage the power of XML" by deprecating it wherever you can for a more sensible cross platform format.
      </rant>


      1. Advocate XML deprecation.
      2. Use XML style conversation markers.
      3. ???
      4. Profit!!!

  6. Re:Who The Hell Still Uses Perl? by andres32a · · Score: 4, Insightful

    Slashdot.org!!

  7. Re:Bah, who the hell still uses perl? by Jah-Wren+Ryel · · Score: 4, Insightful

    As true as that may be, I have never heard of any
    other language be referred to as a "write only language".
    The only point that citing your personal ignorance makes is that you are ignorant.
    --
    When information is power, privacy is freedom.
  8. Re:Who The Hell Still Uses Perl? by TheSkyIsPurple · · Score: 4, Insightful

    I don't know about GP, but I've got a couple hundred hosts that have PERL installed, but not Ruby or Python, and getting those others installed would require alot of work. (some technical, given the age and OS on some of them... but mostly configuration management style issues)

    Since there is alot of PERL code already doing work in this environment, and PERL is on everything already... it makes sense to stick with what's there.

  9. Re:Hello, AC by nuzak · · Score: 4, Insightful

    > The hubris needed to upend this core part of the language is pretty astonishing.

    You mean like the first time he messed around with regexes? Now any regex implementation that doesn't have perl's features is considered a toy. And Perl is merely catching up to Snobol and Icon.

    Perl will do fine despite ignorant fools who sneer at it. Perl6 is still headed to perpetually unreleased oblivion, but some features will hopefully break off and find their way back into perl5 and elsewhere. Regexes among them.

    --
    Done with slashdot, done with nerds, getting a life.
  10. Re:Who The Hell Still Uses Perl? by fyngyrz · · Score: 3, Interesting
    Shitty... as opposed to what, PHP?

    Well, certainly as opposed to Python, anyway. I went from perl to Python with a huge sigh of relief. I try to move a still-used perl script from perl to python once a week. Eventually I'll get them all, and I can leave the language behind. But I wrote tons of perl before I discovered Python and it is a long, long road to upgrade all that stuff. But every time I do one, I get a more maintainable, more english-like tool. Sometimes it takes me several minutes to even understand what the heck a perl script (even one of mine) is trying to do. Perl just... doesn't lead you to the most readable solutions. In fact, the better at it you get, the more obscure looking your programs get, it seems to me. That's an IMHO. :)

    Anyway, if someone is looking for a scripting language today, Python is the cat's meow. Readable, sensible, extensible, flexible, well supplied with great libraries of functionality, powerful as hell, very easy to debug, not unreasonable in speed.

    --
    I've fallen off your lawn, and I can't get up.
  11. I came in here to say this by Wee · · Score: 4, Interesting
    Was exactly what I was going to say. I've used XML::Simple a lot, but only for reading in small documents, like config files. It works well for that. But I'd never use it on something that was bigger than, say, 100K. It's too slow and resource intensive. It does, however live up to its name. It's a very simple interface to an XML doc.

    One thing I user it for was representing a database in XML. Once I had the DB layout in a datastructure, it was one line to print it out. Of course, this was before I knew about DBIx::XML_RDB...

    -B

    --

    Ash and Hickory, straight-grained and true, make excellent bludgeons, dandy for the cudgeling of vegetarians.

  12. Re:Hello, AC by VGPowerlord · · Score: 4, Insightful
    What I find annoying is that core language features are changing operators for no reason other than to change operators.

    Example: -> is changing to . The reason given is

    -> becomes ., like the rest of the world uses.
    Which also forces . to change to ~ (also .= is now ~=)
    Which also forces =~ to change to ~~

    That's three major operators in the language changed with the justification that the rest of the world does one of them differently. Except, by definition, people who already knew perl.
    --
    GLaDOS for President 2016! "Well here we are again. It's always such a pleasure." -- GLaDOS, 2011
  13. Re:Who The Hell Still Uses Perl? by texwtf · · Score: 4, Interesting

    The fact that whitespace is dogmatized by the pyhon community makes the community
    itself less attractive, and the language because of it. It sends the message that
    it doesn't really matter what you want, the language is perfect and your code
    is crap because you are too stupid to agree with how right the community is.

    Guido could _easily_ put in some sort of pragma to allow other types of blocks, it's
    only a matter of arrogance that stops him- coding with whitespace is the "right" way to do it.

    There's also the matter of the parser. The last time I used Python everything was a syntax error, which gave little indication what was actually wrong with a piece of
    code.

  14. Re:Bah, who the hell still uses perl? by Anonymous Coward · · Score: 5, Insightful

    So you have never used APL, eh?

    Perl is derided by people who quite frankly don't have a clue.

    We get lots of flammage from the Java and Python programmers that seem to be unable to grasp that when they try to justify their language choices by putting down other languages, they demonstrate how clearly idiotic their choices are. They cannot come up with something better than "line noise"? My god, have they not heard of the obfuscated code contest?

    One can write unreadable code in any language. Perl is not unique in this regard. Moreover, Perl itself does not admit more unreadable code than other languages. The regex engine in Perl is a language unto itself. You don't need to use it, ever. But once you do, you realize how incredibly powerful it is. And you learn how to parse it, and even more scary, emit it, in your head. What takes hundreds of lines in Java (well what doesnt) becomes single digit number of lines in Perl.

    In my career, I have used APL, Assembly (x86, 8080/Z80, 6502, 6800, F8, ...), Basic, C, C++, Fortran (66,77,90,95), Gauss, Icon, Java, maxima/macsyma, mumath, pascal, perl, prolog, python, ruby, R, VB and probably a few I forget in there. The big idea I have learned is to never force fit a tool to a problem. Select the right tool for the right problem. And go from there.

    Perl is wonderful in that it allows for rapid application development, has a really huge library to draw from (www.cpan.org), orders of magnitude larger than competitive languages, an active developer base, an active contributer base, is portable (you can run Perl anywhere, windows, linux, mac, Cray, AIX, ...). It is not the perfect language for everything though, there are some missing bits.

    Ruby is neat, though I am amused by those in the Java community running over to it, thinking it is better than Perl. It is slightly different, but the syntax is actually quite close to perl. Learning it isn't hard once you know Perl, you can go back and forth quite easily. The problem in Ruby's case is speed. This hopefully will improve over time.

    Python is hard for me to use. I am reminded of BASIC on IBM PCs. Some people like it, I don't. Use it if you must.

    Java has always felt to me to be a solution in search of a problem. I haven't seen things that are being done in Java that couldn't be done more quickly and efficiently in other languages. Java has developed a cult-like following. Many people drank the koolaid, committed company resources to it, and poo-pooed other, better solutions. Only to discover that each "advance" meant to deliver more performance dug people in deeper to the hole, made the systems harder and more expensive to develop. And until recently, the vast majority of people were in significant denial over the fact that java was and is just a marketing gimmick for Sun. They drank the koolaid.

    Fortran ... spent 15 years developing Fortran code. May it never reach 16 years.

    APL. You want write only? Parse this: +/x

    In APL, we wrote complex calculation systems in very few lines. It was a tremendously powerful language.

    In Fortran we wrote complex calculation systems in quite a few lines. Not very powerful for IO, really sucked for this.

    In Perl we drive complex calculation codes written in almost any language. Insanely powerful. Expressive and concise syntax, reads well when well written. Good IO, good networking, good system hooks. Can use MVC and web tools, Jifty even comes with a pony.

  15. Re:Who The Hell Still Uses Perl? by rgravina · · Score: 3, Insightful

    Guido could _easily_ put in some sort of pragma to allow other types of blocks, it's
    only a matter of arrogance that stops him- coding with whitespace is the "right" way to do it.
    There is are very good reasons for having indentation indicate a block.

    Firstly, code written by different programmers is consistently indented. C and Java programmers could argue for a millennia about where to put the curly brace, but in the end the argument is just trivial. If everyone did it the same way code would be much more readable. Sure, the language gives you freedom to work the way you want but it does so at the expense of readability.

    Another reason is that indentation easily shows that one block is the child of another. Again, this makes Python code much more readable than it otherwise would be without it.

    I don't think the decision was a matter of arrogance at all. It's logical, and it makes sense. Programming is often said to be part art, part science, but trading a little bit of expression in the way you indent your code for readability (and hence maintainability) makes sense to me. It does take a bit of getting used to, sure, but it is worth the effort when you come back to the code at a later date, or try to understand someone elses.

  16. Re:Python: syntactiacally significant whitespace.. by Anonymous Coward · · Score: 3, Insightful

    Oh yeah, it's just the absolute end of the world. Just a total show-stopper. After all, who would want readable, maintainable, consistent-looking code in a large team? What a disaster!

  17. Re:Who The Hell Still Uses Perl? by texwtf · · Score: 3, Insightful

    There are very good reasons not to. Thus, dogma. My argument is "everyone else does it the other way, maybe being flexible would be good." Your argument is "I am right and my way is good, so there shouldn't be any other way". That's Guido's argument too.