in reply to Re^2: Escaping a variable
in thread Escaping a variable

print hex($foo), "\n";

The output:

77

Dave

Replies are listed 'Best First'.
Re^4: Escaping a variable
by Draxter (Initiate) on Nov 08, 2011 at 09:35 UTC

    I'll be more specific. How can I get $string and $bar to be the same by the end of this code:

    #!/usr/bin/perl use warnings; use strict; my $bar = "\x04\x4d"; my $foo = "044d"; my $string; while ($foo =~ m/(..)/g) { $string .= chr($1); } print "string: $string\n"; print "bar: $bar\n"; Argument "4d" isn't numeric in chr at roman.pl line 11. string:  bar: M

    Thanks,

    Eran.

      It's easier when you read the directions we pointed to: hex, chr.

      use warnings; use strict; use Test::More; my $bar = "\x04\x4d"; my $foo = "044d"; my $string; while ($foo =~ m/(..)/g) { $string .= chr(hex($1)); } is( $bar, $string, '$bar eq $string' ); done_testing(); print "string: $string\n"; print "bar: $bar\n"; __END__ ok 1 - $bar eq $string 1..1 string: M bar: M

      Update: For the record, Test::More, is(), and done_testing() are not significant to the solution. I used them to demonstrate the equality.


      Dave