ghenry has asked for the wisdom of the Perl Monks concerning the following question:

Dear Master Monks,

I have been playing with Term::ANSIColor and die, the docs say to use print, but I'd thought I'd try it with die anyway.

For some reason however, in the below code, it seems to always include $!, no matter what I do.

Any tips on how to not include this?

if ($install) { # Open the configfile at /etc/myconf.conf my $Config = Config::Tiny->read( $conf ) if -e $conf or die RED, "\n\nError: Config file $conf missing\n\n", RESET; # Just testing print "Installing now\n"; # Reading properties and print to test my $pgpass = $Config->{Postgresql}->{pass}; print "$pgpass\n"; }
Thanks,
Gavin.

Walking the road to enlightenment... I found a penguin and a camel on the way.....
Fancy a yourname@perl.me.uk? Just ask!!!

Replies are listed 'Best First'.
Re: Term::ANSIColor and DIE
by Fletch (Bishop) on May 23, 2005 at 13:14 UTC

    ITYM that it includes the line number information, not $!. But that's because your string doesn't end with \n, it's ending in whatever sequence of escape characters RESET expands out to. You want to put the "\n\n" after the RESET.

    . . . die RED, "Blah blah", RESET, "\n";

    Update: And you might want to test if STDERR is a tty or not before adding escapes to it in case the user is saving it into a file.

    sub maybe_color { my $msg = shift; $msg = RED . $msg . RESET if -t STDERR; return $msg; }

      Ah, yes. I completely forgot about the \n rule.

      Thanks for this and the sub. I'll incorporate that test in my code if you don't mind ;-)

      Gavin.

      Walking the road to enlightenment... I found a penguin and a camel on the way.....
      Fancy a yourname@perl.me.uk? Just ask!!!