Become a fan of Slashdot on Facebook

 



Forgot your password?
typodupeerror
×
Perl Programming

XML::Simple for Perl Developers 186

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."
This discussion has been archived. No new comments can be posted.

XML::Simple for Perl Developers

Comments Filter:
  • by ThatDamnMurphyGuy ( 109869 ) on Saturday February 03, 2007 @09:14PM (#17877798) Homepage
    No, professionals write good code, regardless of the language. There is just as much shitty Python/Ruby out there as there is Perl.
  • by BrianRoach ( 614397 ) on Saturday February 03, 2007 @09:24PM (#17877858)
    "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.)
  • by soapbox ( 695743 ) * on Saturday February 03, 2007 @09:32PM (#17877894) Homepage

    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 [g95.org]--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.

  • good lord... (Score:0, Insightful)

    by Anonymous Coward on Saturday February 03, 2007 @09:33PM (#17877902)

    XML has become pervasive in the computing world and is buried more and more deeply into modern applications and operating systems.

    Man, that's the scariest thing I've read all day. IT'S BURROWING INTO THE SYSTEM!! AHHHH!!!! ANGLE BRACKETS EVERYWHERE!

    Seriously, the first thing that came to mind was the type of stuff you read on thedailywtf.com [thedailywtf.com].. something like: "And then Joe realized that the reason the string_to_upper() was so slow was because it was calling a SOAP service on a machine at the lead developer's previous employer, passing 23K of XML in both directions...." .. And then INVARIABLY, there's a reply that says "Hey, that isn't such a bad idea...."

    So, no thanks, I don't want XML burying itself in my code any more than I want my music player to squirt songs.

  • What? (Score:4, Insightful)

    by cliveholloway ( 132299 ) on Saturday February 03, 2007 @09:47PM (#17877978) Homepage Journal

    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? [google.com]

    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 [yaml.org] or JSON [json.org] instead. XML is a steaming, clumsy overrated turd. I benchmarked XML::Simple [cpan.org] against YAML::Syck [cpan.org] - 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>

  • by andres32a ( 448314 ) on Saturday February 03, 2007 @09:53PM (#17878008) Homepage
    Slashdot.org!!
  • by Jah-Wren Ryel ( 80510 ) on Saturday February 03, 2007 @10:01PM (#17878048)

    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. [wikipedia.org]
  • Hello, AC (Score:3, Insightful)

    by Scareduck ( 177470 ) on Saturday February 03, 2007 @10:31PM (#17878184) Homepage Journal
    There's a reason they're called "Cowards". Those of us who've been around a while know that there are all kinds of languages out there, and plenty of them can be used to write good code. The real problem with Perl is that Larry Wall is slowly losing his mind, adding features that nobody asked for; a good example is the new, backwards-incompatible regexps. (Don't go off that there'll be a compatibility mode; that's beside the point. The hubris needed to upend this core part of the language is pretty astonishing.) Also, he seems to be spending a lot of time with the Parrot rehosting, something else that is (perhaps) of dubious value. The changes are so orthogonal to what I do with Perl (hello, how about faster OO calls?) I have to wonder if there'll ever be a reason to switch to Perl 6. (Perhaps someone out there who knows more can comment.)
  • by TheSkyIsPurple ( 901118 ) on Saturday February 03, 2007 @10:35PM (#17878206)
    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.
  • Re:Hello, AC (Score:5, Insightful)

    by nuzak ( 959558 ) on Saturday February 03, 2007 @10:48PM (#17878258) Journal
    > 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.
  • Re:Hello, AC (Score:3, Insightful)

    by Watson Ladd ( 955755 ) on Saturday February 03, 2007 @11:15PM (#17878364)
    I think the regex syntax change is aimed at reducing the line-noise quality of regexes, as well as making them more expressive. The interpreter change is mostly aimed at pooling the skills of the Perl, Python, and Ruby communities. Even if it looks like a lot of effort now, it will pay off a lot later.
  • Re:Hello, AC (Score:5, Insightful)

    by VGPowerlord ( 621254 ) on Sunday February 04, 2007 @12:19AM (#17878688)
    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.
  • by Anonymous Coward on Sunday February 04, 2007 @01:35AM (#17879082)
    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.

  • by rgravina ( 520410 ) on Sunday February 04, 2007 @02:36AM (#17879318)

    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.

  • by localman ( 111171 ) on Sunday February 04, 2007 @02:43AM (#17879342) Homepage
    In fact, the better at it you get, the more obscure looking your programs get

    Well, I can tell you that's not true. If you're willing to believe me, I'll claim that I've become very proficient at perl in the past 9 years and my code has become much easier to read. I think those who have worked with me would agree. Some have even said so specifically. You just have to have a little self dicipline and a sense of clarity and aesthetics.

    Now, if you don't have such sense, or if you just like another language, that's totally cool. Whatever works for the job. But perl is a medium (like oil or watercolor) and you can make beautiful programs with it. It just doesn't do anything to assist you in that endeavor :) Still, it's my favorite language (I've only ever dug into java and c++ as alternates).

    Cheers.
  • by Anonymous Coward on Sunday February 04, 2007 @03:05AM (#17879404)
    Python is English-like in the sense that VB.NET is English-like, which is to say, nothing at all like English. It's clumsy, unnecessarily verbose, overlogical and obtuse. There's no artistry to it; every Python program looks exactly the same regardless of functionality or intent.

    Perl is for poets. Python is for autistic geeks who wish the world were expressed in maths.
  • by Anonymous Coward on Sunday February 04, 2007 @03:37AM (#17879506)
    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!
  • by texwtf ( 558874 ) on Sunday February 04, 2007 @04:32AM (#17879656)
    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.
  • Indeed. (Score:3, Insightful)

    by Ayanami Rei ( 621112 ) * <rayanami&gmail,com> on Sunday February 04, 2007 @06:01AM (#17879934) Journal
    Java is well-suited for large projects with fairly well defined requirements (and potentially complex interactions between objects/components).

    If the requirements are ill defined, or the system small enough to likely be confined to a single box, or the object model relatively simple (few types, lots of instances) then perl is the first thing I think of...

    Unless the object model is regular and layered, then I think ruby.
    Unless there is a need for blistering IO and syscalltastic goodness with function overloading, then C++
    Unless there isn't a need for too many object tricks or the STL, then C.

    All of the above languages have excellent tools, environments, and libraries. I think they've all got it made in the shade.

    BTW, the easiest language to develop and troubleshoot is JavaScript (ecmascript). Tools like firebug make it stupid-easy. Of course, there's no regularized non-web environment for it; I've seen small efforts to that end but they always end up not going far. It's a real shame, IMHO. Prototyping, lazy-evaluating, duck typing, easy-to-read language... what's not to love?

    I don't know *kicks dirt*
  • by Anonymous Coward on Sunday February 04, 2007 @07:23AM (#17880216)

    These comments are based on C++, though i have used Perl I have been doing much more C++ coding lately.
    Me too a C++ programmer - using xml extensively.

    The XML files are text based. Text I/O has to be read in sequentially whereas you can write out an entire block of allocated memory to the disk in binary format. The advantages of this is that you can read & write that data to and from disk 50 to 100 times faster than reading it in sequential from a text file.

    What advantages does XML provide at the expensive of data i/o speed loss?
    Most xml parsers I have used had the option to read the complete file into memory in large chunks, and perform the actual parsing on the memory stream. So there is no performance penalty compared to binary file loading in terms of I/O.

    The actual performance penalty comes from the actual parsing, which is of course slower than just memcpy()'ing memory-ready binary data into place. I have spent a whole lot of time on this performance issue and have found (the hard way) that the key to speeding this up lies in optimizing the xml document structure. Take it as a given that most xml tutorials advocate sub-par structure for the sake of simplicity.

    Take a look at https://collada.org/public_forum/welcome.php [collada.org] for a good optimized xml-based format.

    regards,

2.4 statute miles of surgical tubing at Yale U. = 1 I.V.League

Working...