in reply to Trouble working with Config::Simple

Perl doesn't do tilde expansion—that's a shell thing. Your last line would need to be:

$cfg->write("$ENV{HOME}/.kenesis");

Also, you're missing a semi-colon on the $special_item line.

Update: Config::Simple apparently reports errors (in write(), for instance) with false return values. As such, you could have known what was up with code like this:

$cfg->write("~/.kenesis") or die $cfg->error();

Reports:

'~/.kenesis' couldn't be opened for writing: No such file or directory

Replies are listed 'Best First'.
Re^2: Trouble working with Config::Simple
by almut (Canon) on Jun 30, 2008 at 20:33 UTC
    '~/.kenesis' couldn't be opened for writing: No such file or directory

    I doubt, though, that this message would have helped a lot here.  Someone starting out with the conviction that ~ (tilde) would work from Perl like it does in the shell, would probably have begun wondering why their home directory isn't writable for themselves, or some such... :)

      The message is telling exactly what's wrong. There is no directory '~'. It doesn't say anything about a "permission denied". So, there's no need to wonder.

      I think if it would do a ~ expansion, it should state the expanded path in the error message (just like the shell does).

      $ touch ~/test.txt $ chmod a-w ~/test.txt $ echo "string" > ~/test.txt bash: /home/user/test.txt: Permission denied $
        The message is telling exactly what's wrong.

        Sure it is. But the point is how you'd interpret the message if you think that '~' stands for your home directory. Of course, once you reckon what the problem is, it's all nice and dandy.

        Honestly, if some message reports a problem with ~/somefile, would your first thought be that the real problem is that ~ has nothing to do with your home directory? Even details such as "Permission denied" vs. "No such file or directory" etc., or whether the shell would normally expand tilde in an error message, might not immediately point in the right direction. — Believe me, I've seen rather skilled programmers tricked by this...

      That's true, but it would have been a good clue to us. I started answering the OP without even knowing how Config::Simple reports errors. Having the error in front of me would have gotten me to the answer faster.