Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Use of "my" after Perl v5.14

by marinersk (Chaplain)
on Sep 20, 2012 at 22:37 UTC ( #994771=note: print w/ replies, xml ) Need Help??


in reply to Use of "my" after Perl v5.14

I missed one of your questions, apologies:

Significance of "my": It has a measurably distinguished behavior distinct from "our". Most notably useful in Modules.

Pay attention to the value of $TRUE in the sample:

This is t2.pm:

#!/usr/bin/perl use strict; package t2; # -------------------------------------------------------------------- +---------- # Constants (Operationally, if not technically) # -------------------------------------------------------------------- +---------- our $RET_SUCCESS = 0; our $RET_FAILURE = (-1); our $RET_FATAL = (-2); my $TRUE = 1; my $FALSE = 0; # -------------------------------------------------------------------- +---------- # version() - Returns the version number of this module # -------------------------------------------------------------------- +---------- sub version { return sprintf "0.10a"; } # -------------------------------------------------------------------- +---------- # Perl modules MUST return true # -------------------------------------------------------------------- +---------- 1; __END__

This is t3.pl:

#!/usr/bin/perl use strict; use t2; print "our: \$t2::RET_FAILURE = '$t2::RET_FAILURE'\n"; print " my: \$t2::TRUE = '$t2::TRUE'\n"; exit; __END__


Comment on Re: Use of "my" after Perl v5.14
Select or Download Code
Re^2: Use of "my" after Perl v5.14
by Rohit Jain (Sexton) on Sep 20, 2012 at 22:55 UTC

    I think $TRUE variable will not be visible in second file from t2 package.. Because it is declared to be private in that package.. Will it show compiler error??

      I didn't get an error. But then I am not using v5.14.
        I didn't get an error. But then I am not using v5.14.

        You're also not using warnings, which would have made Perl complain about "Use of uninitialized value $t2::TRUE in concatenation (.) or string at t3.pl line 7" (line 7 in my altered file) regardless of Perl version. Note also that
            print " my:  \$t2::TRUE        = '$t2::TRUE'\n";
        prints
            my:  $t2::TRUE        = ''
        (empty single-quotes instead of '1') with or without warnings.

        Update: Upon re-reading your post, it occurs to me that your intention may have been to point up the fact that the value of the lexical  $TRUE defined in the  .pm file is not visible in the  .pl file ("Pay attention to the value of $TRUE in the sample..."). If so, I offer my own apologies! (In any event, the use of warnings remains a valuable, albeit implicit, recommendation.)

Re^2: Use of "my" after Perl v5.14
by Rohit Jain (Sexton) on Sep 20, 2012 at 22:58 UTC
    And apologies accepted :)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (14)
As of 2014-07-28 12:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (196 votes), past polls