Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Welcome to the Monastery
 
PerlMonks  

Re: (XML::Parser) Finding and fixing a bug

by grantm (Parson)
on Apr 21, 2003 at 21:50 UTC ( #252135=note: print w/ replies, xml ) Need Help??


in reply to (XML::Parser) Finding and fixing a bug

I'm still struggling to understand what the original (buggy) code was trying to achieve. Was it to enable something like this to actually work:

use XML::Parser; open CONFIG, ('config.xml') || die $!; my $parser = XML::Parser->new(Style => 'Tree'); my $config = $parser->parse('CONFIG');

If so, that doesn't seem to work even using the unpatched version of the module. Can anyone give a working example of providing a symbol name to the parse method? If the original code does not actually work as intended, then a patched version wouldn't need to worry about backwards compatibility.


Comment on Re: (XML::Parser) Finding and fixing a bug
Download Code
Re: Re: (XML::Parser) Finding and fixing a bug
by Juerd (Abbot) on Apr 21, 2003 at 23:19 UTC

    my $config = $parser->parse('CONFIG');

    my $config = $parser->parse(*CONFIG);
    But that would better be checked with something like ref(\$arg) eq 'GLOB'.

    But... XML::Parser::Expat::parse allows strings to be used. In your try, it'll try to use XML::Parser::Expat::CONFIG. Things change if your symbolic reference contains :::

    my $config = $parser->parse('main::CONFIG');
    It is unlikely that someone uses a string constant there, but it COULD be some $foo that is the result of whatever, which could in turn be some stringified version of *CONFIG. *CONFIG stringifies to *main::CONFIG, and with that * there it still works:
    my $config = $parser->parse('*main::CONFIG');

    I didn't want to break (stupid) code like this:

    sub something_that_stringifies { "$_[0]" } my $fh = something_that_stringifies *CONFIG; my $config = $parser->parse($fh);

    Juerd
    - http://juerd.nl/
    - spamcollector_perlmonks@juerd.nl (do not use).
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (10)
As of 2014-04-21 08:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (492 votes), past polls