I realized after the fact, that looking at some of the different ways you can write numbers in perl.
$n = 1234; # decimal integer $n = 0b1110011; # binary integer $n = 01234; # octal integer $n = 0x1234; # hexadecimal integer $n = 12.34e-56; # exponential notation $n = "-12.34e56"; # number specified as a string $n = "1234"; # number specified as a string http://man.openbsd.org/perlnumber On Tue, Jul 21, 2020 at 05:24:34PM -0700, Andrew Hewus Fresh wrote: > On Tue, Jul 21, 2020 at 07:10:34PM -0500, Edgar Pettijohn wrote: > > I was playing around with the hex function in perl. So naturally I > > started with: > > > > perldoc -f hex > > > > Which showed me a few examples namely the following: > > > > print hex '0xAf'; # prints '175' > > print hex 'aF'; # same > > $valid_input =~ /\A(?:0?[xX])?(?:_?[0-9a-fA-F])*\z/ > > > > However, I get the following output: (newlines added for clarity) > > > > laptop$ perl -e 'print hex '0xAf';' > > 373 > > so, you're double-use of single quotes here causes some fun shell > processing. This is the same as: > > perl -e 'print hex 0xAf' > > (although let me re-do that with -E and say) > > $ perl -E 'say hex 0xAf' > 373 > > Well, as you say, that's not what you expect. > > But, perhaps there is an explanation. Lets try without hex. > > $ perl -E 'say 0xAf' > 175 > > interesting, but where's the hex? > > $ perl -E 'say hex 175' > 373 > > ahh, there it is. > > Just to get back on the original page though and avoid the shell > confusion, lets try one last thing. > > $ perl -E 'say hex "0xAf"' > 175 > > And that work. Although I guess we can also > > $ perl -e 'print hex "0xAf"' > 175 > > if you'd like. > > > > laptop$ perl -e 'print hex 'aF';' > > 175 > > > > I'm guessing there is a bug here but not sure if its software or > > documentation. > > > > Thanks, > > > > Edgar > > > > -- > andrew - http://afresh1.com > > Hey! It compiles! Ship it! > -- andrew - http://afresh1.com Hey, I think I see a barn up ahead. -- The American Astronaut