Perl Monk, Perl Meditation PerlMonks

### Re^2: A philosophical pondering concerning hexes

by diotalevi (Canon)
 on Jun 24, 2004 at 13:13 UTC ( #369339=note: print w/replies, xml ) Need Help??

No, the result of oct("108") is "8" but I think it should be undef.

Replies are listed 'Best First'.
Re: A philosophical pondering concerning hexes
by Abigail-II (Bishop) on Jun 24, 2004 at 13:26 UTC
How do your statements: No, I didn't give oct a valid hex number, I gave it an invalid octal number which could have been understood as an otherwise valid decimal number. and No, the result of oct("108") is "8" but I think it should be undef. relate to each other? 108 is an otherwise valid decimal number. You also seem to be defending, or at least sharing, the OP's ideas. And the OP wants to have a function that given decimal input, returns the decimal representation - so oct 108 (or whatever name this function has) should return 108.

If you think that oct 108 should be undefined, and not 8, do you also think that \$x = "10 dogs" + "5 chickens" should result in \$x being undefined, and not 15? What about

```print "Please enter a number: ";
my \$num = <>;
printf "Its square is %d.\n" => \$num * \$num if \$num =~ /^\d+\$/;
Should that print "Its square is 0.", after issueing a warning?

Abigail

I had not noticed previously that oct( "108" ) == 8 because oct( "10" ) == 8 and "108" =~ /^[0-7]+/. My initial thought on seeing 8 out of "108" was that oct() was returning some sort of nonsense value. I get it now that it is the same thing as oct( "10 foo" ).

Thanks.

Create A New User
Node Status?
node history
Node Type: note [id://369339]
help
Chatterbox?
and John Coltrane plays...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (11)
As of 2017-08-22 15:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Who is your favorite scientist and why?

Results (337 votes). Check out past polls.

Notices?