Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

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

by Don Coyote (Hermit)
on Nov 22, 2019 at 16:32 UTC ( [id://11109070]=note: print w/replies, xml ) Need Help??


in reply to Converting to number doesn't always work...

The question of whether perl will return a string or number, which is thouroughly interesting, is a bit of a side issue.

What you seem to be attempting to do is change a lexically scoped variable from a different scope.

use strict; use warnings; #use vars ('$M','$N'); # local $SIG{__WARN__} = sub { $N=24 }; my $t_num = sub { $N=24 }; printf "\nThe value of N is now %s %d %o\n",$N,$N,$N; $M = sprintf "%x", 41; printf "\nThe value of M is now %s %d %o\n",$M,$M,$M; my $t_var = sub { $M = 42; # printf "\nThe value of M is now %s %d %o\n",$M,$M,$M; sub { $M }; }; printf "\nThe value of t_var is now %s %d %o\n",$t_var->(),$t_var->( +),$t_var->(); printf "\nThe value of M is now %s %d %o\n",$M,$M,$M; =head1 output Global symbol "$N" requires explicit package name at v42_13.pl line 10 +. Global symbol "$N" requires explicit package name at v42_13.pl line 11 +. ... Global symbol "$M" requires explicit package name at v42_13.pl line 23 +. Global symbol "$M" requires explicit package name at v42_13.pl line 23 +. Execution of v42_13.pl aborted due to compilation errors. =cut =head uncommented 'use vars ('$M','$N');' output Use of uninitialized value $N in printf at v42_13.pl line 11. Use of uninitialized value $N in printf at v42_13.pl line 11. Use of uninitialized value $N in printf at v42_13.pl line 11. The value of N is now 0 0 The value of M is now 29 29 35 The value of t_var is now CODE(0xxxxxxxxxx) dddddddd ddddddddddd The value of M is now 42 42 52 =cut

If you change the scope then you can probably put your local pc repair shop on speed-dial. I would advise not doing this with environment variables.

additional not sure about this really, though, I'd have thought if this was an issue here, there would have been some more responses of the kind. I may have misunderstood this a little.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11109070]
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: (4)
As of 2024-04-23 06:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found