Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^5: Converting to number doesn't always work...

by Don Coyote (Hermit)
on Nov 25, 2019 at 18:51 UTC ( [id://11109192]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Converting to number doesn't always work...
in thread Converting to number doesn't always work...

expanding on AnomalousMonk's code and haukex's, it does seem like the sig handler has something to do with this. It appears to be activating the NV slot of the scalar.

When perl then does its DWIM conversions, it is preferring the double over the int, so I would percieve that the scalar is something a little more complex than just a dualvar.

Also worth noting sig handling on some operating systems are implemented differently. how much impact this is having I am unsure of

use strict; use warnings; use Devel::Peek; $|++; my @TEST_VALUES = ('a55','55a'); foreach my $i (@TEST_VALUES) { print qq{\nCalling TEST('$i') / \n}; print qq{\nTEST return values = @{[ TEST($i) ]} \n\n}; } sub TEST { my $N = shift; local $SIG{__WARN__} = sub { $|++; print "in_warn\n"; # my $subref = sub { $|++; print "in_subref\n"; Dump $N; print qq{(warn: N=$N -> }; $N = 77; print qq{N=$N) / \n}; Dump $N; print "outta_subref\n"; }; print "in_test\n"; Dump $N; # my $tmp_value = $subref->(); print qq{N=$N / N+0=}, $N + 0; print qq{ / N.''=}, $N.'', qq{\n}; print "outta_test returning $N, $N+0, $N.''\n"; return $N, $N+0, $N.''; } =head1 output Calling TEST('a55') / in_test SV = PV(0x10a847c) at 0xf9d3dc REFCNT = 2 FLAGS = (PADMY,POK,pPOK) PV = 0xf9055c "a55"\0 CUR = 3 LEN = 12 in_warn SV = PVNV(0x10a9bcc) at 0xf9d3dc REFCNT = 2 FLAGS = (PADMY,POK,pPOK) IV = 0 NV = 0 PV = 0xf9055c "a55"\0 CUR = 3 LEN = 12 (warn: N=a55 -> N=77) / SV = PVNV(0x10a9bcc) at 0xf9d3dc REFCNT = 2 FLAGS = (PADMY,IOK,POK,pIOK,pPOK) IV = 77 NV = 0 PV = 0xf9055c "77"\0 CUR = 2 LEN = 12 outta_subref N=a55 / N+0=0 / N.''=77 outta_test returning 77, 77+0, 77.'' TEST return values = 77 0 77 Calling TEST('55a') / in_test SV = PVNV(0x10a9bcc) at 0xf9d3dc REFCNT = 2 FLAGS = (PADMY,POK,pPOK) IV = 0 NV = 0 PV = 0xf9055c "55a"\0 CUR = 3 LEN = 12 in_warn SV = PVNV(0x10a9bcc) at 0xf9d3dc REFCNT = 2 FLAGS = (PADMY,POK,pPOK) IV = 0 NV = 55 PV = 0xf9055c "55a"\0 CUR = 3 LEN = 12 (warn: N=55a -> N=77) / SV = PVNV(0x10a9bcc) at 0xf9d3dc REFCNT = 2 FLAGS = (PADMY,IOK,POK,pIOK,pPOK) IV = 77 NV = 55 PV = 0xf9055c "77"\0 CUR = 2 LEN = 12 outta_subref N=55a / N+0=55 / N.''=77 outta_test returning 77, 77+0, 77.'' TEST return values = 77 55 77 =cut

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11109192]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-03-29 13:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found