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!