in reply to reading octal values from file

When you are reading from the file, the value of $test{bell} will be a four character string, consisting of a backslash, two zero's and a seven. "\007" is only going to be interpreted a bell character if it appears like this in the program text.

You might want to use an eval, or chr substr $2, 1.

Abigail

Replies are listed 'Best First'.
Re: Re: reading octal values from file
by Melly (Chaplain) on Feb 27, 2003 at 17:16 UTC

    Many thanks.

    I've now ended up with the following code (and I'm just putting an integer in the option file - i.e. nak:6)

    I'm also allowing for a string, such as "OK", but can anyone suggest a more elegant solution than the following?

    if($opt{ack} =~ /^\d+$/){ print $live_socket chr($opt{ack}); } else{ print $live_socket $opt{ack}; }
    Tom Melly, tom@tomandlu.co.uk
      Does this help with any ideas?
      use strict; my %test; $test{bell} = 'this is my \007'; $test{bell} =~ s!\\(0\d\d)!chr($1)!ge; print $test{bell} . "bell\n";

      --

      flounder