Click here to get back home

Different behavior between eval "07" and eval "08"

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Different behavior between eval "07" and eval "08" Liang Wang 02-01-2008
Posted by Liang Wang on February 1, 2008, 9:59 pm
Please log in for more thread options
eval "07" gets 7 but eval "08" gets an undefined value. I tested perl
5.8.8 on fedora 8 and ubuntu.

Is there any difference between those two eval statements? Is this a
bug?


Posted by John W. Krahn on February 1, 2008, 10:19 pm
Please log in for more thread options
Liang Wang wrote:
> eval "07" gets 7 but eval "08" gets an undefined value. I tested perl
> 5.8.8 on fedora 8 and ubuntu.
>
> Is there any difference between those two eval statements? Is this a
> bug?

No, there is no difference in the eval statements. The problem is that
"08" is not a valid octal number.


John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall

Posted by Liang Wang on February 1, 2008, 10:27 pm
Please log in for more thread options
> Liang Wang wrote:
> > eval "07" gets 7 but eval "08" gets an undefined value. I tested perl
> > 5.8.8 on fedora 8 and ubuntu.
>
> > Is there any difference between those two eval statements? Is this a
> > bug?
>
> No, there is no difference in the eval statements. The problem is that
> "08" is not a valid octal number.
>
> John
> --
> Perl isn't a toolbox, but a small machine shop where you
> can special-order certain sorts of tools at low cost and
> in short order. -- Larry Wall

Got it. Thanks.

I've tested "06", but not "09". What I really want to do is to
transform string "08" to integer 8. But in this case, eval doesn't
treat "08" as string, as you said.

Posted by John W. Krahn on February 2, 2008, 12:59 am
Please log in for more thread options
Liang Wang wrote:
>> Liang Wang wrote:
>>> eval "07" gets 7 but eval "08" gets an undefined value. I tested perl
>>> 5.8.8 on fedora 8 and ubuntu.
>>> Is there any difference between those two eval statements? Is this a
>>> bug?
>> No, there is no difference in the eval statements. The problem is that
>> "08" is not a valid octal number.
>
> Got it. Thanks.
>
> I've tested "06", but not "09". What I really want to do is to
> transform string "08" to integer 8. But in this case, eval doesn't
> treat "08" as string, as you said.

The string "08" is already the integer 8.

$ perl -le' $x = "08"; print $x; print $x + 1'
08
9



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall

Posted by Tad J McClellan on February 2, 2008, 7:21 am
Please log in for more thread options

> What I really want to do is to
> transform string "08" to integer 8.


Why do you think you need to transform string "08" to integer 8?

Values in Perl are both strings and numbers simultaneously.

You really should review the "Scalar values" and
"Scalar value constructors" sections in perldata.pod.


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher0cmdat/"

Similar ThreadsPosted
help with eval September 29, 2004, 12:24 am
if {} vs eval {} if October 12, 2004, 9:35 am
eval or something else September 21, 2006, 6:35 am
RHS of s/LHS/RHS/ with $1, $2, etc. without "eval"? June 4, 2008, 9:49 pm
double eval? July 18, 2004, 4:28 pm
no re 'eval' not secure enough August 20, 2004, 12:08 pm
eval function October 20, 2004, 2:09 pm
Anyone understands eval? March 17, 2005, 7:10 pm
eval not work June 6, 2005, 5:17 pm
Eval not reseting December 23, 2005, 8:03 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap