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.


In reply to Re: Converting to number doesn't always work... by Don Coyote
in thread Converting to number doesn't always work... by harangzsolt33

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.