Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Escapes and comments in Config::General

by John M. Dlugosz (Monsignor)
on Mar 22, 2011 at 13:33 UTC ( [id://894796]=perlquestion: print w/replies, xml ) Need Help??

John M. Dlugosz has asked for the wisdom of the Perl Monks concerning the following question:

I had a line in my conf file that was something like:
  foo   16′ roll
and when I read it in I got “16&”. Ah, the # starts a comment. So I changed it to
  foo   16&\#x2032; roll
And now I get “16&\#2320 roll” !

The backslash stopped the # from being a comment, but the slash itself was also in the string!

There is an example of this in the manual, so it is clearly supposed to work that way.

I just can't win today <sigh>. What's going on here?

Replies are listed 'Best First'.
Re: Escapes and comments in Config::General
by toolic (Bishop) on Mar 22, 2011 at 13:57 UTC
    I can't reproduce your stated result; I don't see a backslash in the string. I am using Config::General version 2.50 which I just downloaded from CPAN:
    $ cat rcfile foo 16&\#x2032; roll $ $ cat 894796.pl #!/usr/bin/env perl use warnings; use strict; use Config::General; my $conf = Config::General->new('rcfile'); my %config = $conf->getall(); print $config{foo}, "\n"; $ ./894796.pl 16&#x2032; roll $
      OK, I updated to 2.5 (from 2.48) and it works fine!

      I see something about "missing a #" in some other bug fix, in the change log.

      Thanks for mentioning the latest version detail in your post.

      —John

Re: Escapes and comments in Config::General
by young_david (Friar) on Mar 22, 2011 at 14:05 UTC
        My code that reads the file:
        method fetch { if (!defined($data) || (my $age= -M $conffilename)) { # must (re)load the file my $conf= new Config::General:: (-ConfigFile => $conffilename, -UT +F8 => 1); my %result= $conf->getall; $data= \%result; $fileage= $age; } return $data; }
        This is a Catalyst "Model", and the resulting hash winds up in a stash passed to Template::Alloy.
        <p>[% sp.priceline %]</p>
        etc.

    Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Domain Nodelet?
    Node Status?
    node history
    Node Type: perlquestion [id://894796]
    Approved by Corion
    Front-paged by Corion
    help
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this?Last hourOther CB clients
    Other Users?
    Others making s'mores by the fire in the courtyard of the Monastery: (4)
    As of 2024-03-29 08:09 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found