Skip to content

Commit

Permalink
- Fixed a minor issue in Perl.to_sidef() method.
Browse files Browse the repository at this point in the history
When a string that looks like a number, starts with "0[0-9]", is actually a string, so it will be returned as a string.

Example:

	say Perl.eval("'00'")	#=> "00"   (previously was `0`)
	say Perl.eval("'01'")	#=> "01"   (previously was `1`)
	say Perl.eval("'001'")	#=> "001"  (previously was `1`)
  • Loading branch information
trizen committed Oct 4, 2024
1 parent 0d9ec08 commit 2d6af54
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Sidef/Types/Perl/Perl.pm
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ package Sidef::Types::Perl::Perl {

if ($ref eq '') {

if (Scalar::Util::looks_like_number($val)) {
if (Scalar::Util::looks_like_number($val) and $val !~ /^0[0-9]/) {

if ($val =~ tr/e.//) { # parse as float
return Sidef::Types::Number::Number::_set_str('float', "$val");
Expand Down
6 changes: 6 additions & 0 deletions scripts/Tests/perl_eval.sf
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ do { # Recursive Fibonacci in Perl
assert_eq(Num(f(12)), 144)
}

assert_eq(Perl.eval("'00'"), "00")
assert_eq(Perl.eval("'000'"), "000")
assert_eq(Perl.eval("'010'"), "010")
assert_eq(Perl.eval("'00111'"), "00111")
assert_eq(Perl.eval("'0.1'"), 0.1f)

#=================================
# Transparent sub-call with module
#=================================
Expand Down

0 comments on commit 2d6af54

Please sign in to comment.