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."
Sweet! (Score:1)
Re: (Score:2)
XML::LibXML is where it's at (Score:5, Informative)
Re:XML::LibXML is where it's at (Score:4, Informative)
What? (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? [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>
Re: (Score:1)
Re: (Score:1)
Re: (Score:1)
Perhaps XML::Simple is easier to use, but your line of reasoning is like saying it is harder to buy a Ford than a Chevy so buy the Chevy. Built on extremely flawed reasoning.
I'm not saying buy anything or use anything or whatever. I'm just saying the article is pointless.
CPAN do
Re: (Score:2)
How do you process YAML or JSON in Javascript (eg. in a browser)? Most browsers have built-in support for processing XML.
Re: (Score:1)
http://www.json.org/js.html [json.org]
is one.
Re: (Score:2)
Re: (Score:2)
Wow, that must be great having support for XML built into Javascript.
Oh, by the way, JSON is expressed in valid Javascript syntax. That means JSON is already Javascript. No libraries or support necessary.
Sorry for the snarkiness. 'Been struggling with some XML code. That always puts me in a bad mood.
Re:What? (Score:5, Funny)
</rant>
1. Advocate XML deprecation.
2. Use XML style conversation markers.
3. ???
4. Profit!!!
Re: (Score:2)
lameness filter encountered - need this line to post...
Re: (Score:2)
Re: (Score:2)
No, I understand that it *can* be well used, just that for 90% of the applications it *is* used for appear to only be using it because the author once read somewhere that leveraging XML was the way forward. If you're dealing with data storage only, XML is always the wrong answer(*).
cLive
(*) unless the question is, "What is the worst format to store configuration data in?"
Re: (Score:1, Funny)
I can think of worse. How about a flat namespace populated with pairs of the form (name, number). After that list, you can have a giant (about 2^19940 bytes long) of 8 byte values, related to the pairs as follows: the key with name 'pair' has the value stored in the M(number)th bin, where M is the Mersenne Twister function. [wikipedia.org]
Re: (Score:1)
is this a strawman attack? (Score:2)
Re: (Score:2)
Thanks (Score:2)
Re: (Score:2)
Re: (Score:2)
what a coincidence (re: XML::Tiny) (Score:2)
hmm (Score:3, Informative)
Re: (Score:1)
Re: (Score:2)
A good tool for small tasks, but... (Score:3, Interesting)
I came in here to say this (Score:5, Interesting)
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
Re: (Score:2)
Hey now, it depends on the context. Sometimes it is good to just put text into a huge data structure. Sometimes it's not. In the end, a smart programmer who understands the issues is better than a rule.
Cheers.
Simple is not good (Score:2, Informative)
XML data structure serialization (Score:2, Informative)
It makes it really easy to manipulate data in XML format.
However, qore supports deserialization of mixed text and data and multiple out-of order elements, XML attributes (imagine parsing a docbook file for example), as well as serialization (conversion of a qore data structure to an XML string) with the same features.
The same limitations regarding streaming input and very large files affect this approach, but in all
XSLT can't do arithmetic? WTF? (Score:2, Informative)
That's just
Then he formats a number -- because XSLT, of course, doesn't have a format-number() [w3schools.com] function.
Next article -- why you should commute to work in an airplane because, as everyone knows, cars can't turn corners.
No, XSLT doesn't count (Score:2)
Not only is the syntax horendously complex, but there are major misimplemented features that force strange and illogical workarounds, but people used to real programming languages have a really hard time grasping the template style leading to even more frustrations.
XSLT is a complete paradox, on one hand it's supposed to let non-programmers manipulate xml, but at the same time it's so hard to use that pr
Nice for simple data translation (Score:2)
Once again blocked by the install instructions ... (Score:2)
Re:Once again blocked by the install instructions (Score:2)
http://sial.org/howto/perl/life-with-cpan/non-roo
Re: (Score:2)
I wonder what's going on here?
Re: (Score:1, Flamebait)
http://haskell.org/ [haskell.org]
Re:Who The Hell Still Uses Perl? (Score:5, Insightful)
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.)
Re: (Score:2, Interesting)
I tend to use Python for most things, and consider it a general purpose language, suitable for all but performance critical tasks. I'd put Perl and Ruby in the same basket, as general languages with many libraries which just help you get things done. To me, these languages seem pretty interchangeable in this respect. In that case,
Re:Who The Hell Still Uses Perl? (Score:5, Insightful)
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: (Score:1)
Re: (Score:2)
Re: (Score:2)
> PERL
Just an fyi ... Perl isn't an acronym and that capitalization is used to recognize inexperienced Perl programmers. My guess is you don't like Perl becuase you never really got into it. Perl vs Python vs Ruby vs Pike is a pretty silly thing to argue. It's largely a matter of preference like vim vs emacs. So the whole argument is ridiculous...
But Perl isn't an acronym.
Re: (Score:2)
You kidding? I love perl. I never said anything against it.
Don't read too much into a typo my friend =-)
Re: (Score:2)
Re: (Score:2)
Re: (Score:2)
Re: (Score:1, Flamebait)
A well-designed programming language enables great programmers to create masterworks, encourages good programmers to produce great code, and makes bad programmers go looking for another profession.
Perl causes great programmers to produce good-enough code, makes good programmers produce bad code, and enables bad programmers to consider themselves software experts.
That said, anything that permits programmers in any language to work in XML is probably a good thing. Might teach them a few things about st
Perl supports comments... (Score:3, Interesting)
The problem with Perl isn't the language. OK, let me amend that: s/ (t)/just $1/. Its that the culture which surrounds the language encourages practices which are at odds with maintainability. You can't seperate Perl code from Perl coders, and Perl coders are, to a disturbing degree, prone to creating unmaintainable cr
Re:Who The Hell Still Uses Perl? (Score:5, Insightful)
Hello, AC (Score:3, Insightful)
Re:Hello, AC (Score:5, Insightful)
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.
Hello Nuzak (Score:2)
Re: (Score:2)
Re: (Score:2)
Re: (Score:3, Insightful)
Re:Hello, AC (Score:5, Insightful)
Example: -> is changing to . The reason given is Which also forces . to change to ~ (also
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.
Perl6 (Score:2)
Re: (Score:1)
Re: (Score:2, Informative)
The Apocalypses and Synopses (which somehow you managed to quote without reading the surrounding context) explain the reasons for the changes.
Re: (Score:2)
is not a strong enough justification to change operators in a non-backward compatible way. It takes everything you've learned and throws it out the window. What is the incentive to me, as a developer, to learn Perl 6 over another language, since I have to relearn everything from scratch?
Also, why continue to call it Perl if the entire language's syntax changed? It wo
Re: (Score:2)
You're right, there are some things that stayed the same. For example, prescript and postscript... assigning values to a variable (but NOT to an element of an array or hash, that syntax has changed)
However, the list of what HAS changed appears to be much longer:
Array manipulation, renaming operators, OO, Regex, the list goes on...
Re: (Score:2)
Yeah, except as a sign of all the other pointless churn in Perl6, they're not called "rules" anymore. It's back to calling them regexes, even the new production-rule kind. No doubt it'll flip back to "rules" a couple more times this year.
I love perl, but perl6 is doomed thanks to bikeshed-painting like this.
Re: (Score:2)
Re:Who The Hell Still Uses Perl? (Score:4, Interesting)
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.
Python: syntactiacally significant whitespace..... (Score:3, Funny)
Re:Python: syntactiacally significant whitespace.. (Score:3, Insightful)
Re: (Score:2)
Re: (Score:3, Interesting)
Yeah, but once you screw up the indents in a whole file of Python source, you're not going to think that this is such a great thing. See, if you accidentally flatten out the indents of Python code, you have no clue where blocks used to begin and end. If the same thing happened in Perl, you could easily straighten things out by using the curlies as cues. (Heck, my editor will fix indents automatic
Re: (Score:2)
Yeah, but once you screw up the indents in a whole file of Python source, you're not going to think that this is such a great thing. See, if you accidentally flatten out the indents of Python code, you have no clue where blocks used to begin and end.
Yeah; I've seen quite a bit of this problem from my experiments with python. Usually, it comes about when trying to exchange code via email. Lots
Re: (Score:3, Insightful)
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,
Re: (Score:1, Insightful)
Perl is for poets. Python is for autistic geeks who wish the world were expressed in maths.
Re: (Score:2)
Re: (Score:2)
They sure as fuck aren't moving to a language that doesn't even have the same capabilities of use strict;. Yeah, we all just love how python ignores typos in variable names because it has no concept of a declaration.
Re:Who The Hell Still Uses Perl? (Score:4, Interesting)
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.
Re: (Score:3, Insightful)
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 r
Re: (Score:3, Insightful)
Re: (Score:2, Interesting)
Hopefully you'll then realise how non-portable a white-space-based convention is.
Re: (Score:2)
I find python's "half open ranges" and lack of variable declaration far more irritating than anything else.
Re: (Score:2)
itself less attractive, and the language because of it
This put me off python for a long time, too. "Whitespace is not actually evil--it is just misunderstood" is a lesson I learned from SGML-based text processing, where concepts like "ignorable whitespace" reflect the reality of how strangely humans interpret such things.
But once you get over the fact that a fundamental aspect of the language's structure is based on a characte
Re: (Score:2)
Only a PERL programmer would think that is a good idea
Re: (Score:2)
From the PHP Tutorial [w3schools.com]
Re:Bah, who the hell still uses perl? (Score:5, Insightful)
Re: (Score:2, Troll)
Re:Bah, who the hell still uses perl? (Score:4, 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 [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.
Re: (Score:3, Funny)
Re:Bah, who the hell still uses perl? (Score:5, Insightful)
Re: (Score:1, Flamebait)
Regardless, even though the reputation is a shared one that doesn't make it a good thing.
Re: (Score:2)
Re:Bah, who the hell still uses perl? (Score:5, Insightful)
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,
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,
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
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.
Underestimating Java (Score:3, Interesting)
Indeed. (Score:3, Insightful)
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 overloa
Re: (Score:2)
I personally know of far more businesses that consider C/C++ to be "write only" and consider Perl in the same way.
Re: (Score:2)
While many languages have excess baggage (like semicolons) simply because their designers didn't want to stray too far from the languages that inspired them, Perl is the only language out there that is made up entirely of this baggage. It's a Frankenstein's Monster of dead language ideas.
Also, Perl, above all other languages I have used, Perl seems to have been been designed with the philosophy "complexity is good." Today, this philosophy is alm
Re: (Score:1)
Re: (Score:2)
Because you see, despite the fact that programmers like to pretend that they're supremely rational they're actually as faddish as a bunch of teenagers.
Re: (Score:2)
Re: (Score:2)
Indeed. XML is great at bridging gaps. Programmers with very different languages, platforms and viewpoints can exchange it. However, I've become increasingly aware of the space and time hit. Which depends, of course, on the app.
Actually, as long as the sender and receiver are in C, XML has not been the bottleneck for me yet. I do have one Perl XML sender (using XML::Simple) which is a bottleneck.
One way to solve the