http://qs1969.pair.com?node_id=830730

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have come accross the code where in the global variable $st_mode is been accessed as $'st_mode what does the single quote in the variable $'st_mode refer to? Similarly there is a function call &'Stat so i am curious enough to know the real usgae of the quote

Replies are listed 'Best First'.
Re: Need to know on the differnece between the usgae of $st_mode and $'st_mode what does the single quote refer to
by ikegami (Patriarch) on Mar 25, 2010 at 05:45 UTC
    $'var is an obsolete notation for $::var, which is also known as $main::var

        For CPAN historians, this trick was also used by what I believe is the first CPAN joke module (D'oh), released several years before the Acme namespace was invented by TheDamian in 2001:

        I've also seen it employed in Perl Poetry, obfu and even golf (to improve the tie breaker by replacing sub SomeSub{...} with sub'SomeSub{...}).

Re: Need to know on the differnece between the usgae of $st_mode and $'st_mode what does the single quote refer to
by Anonymous Monk on Mar 26, 2010 at 12:04 UTC
    So is this the same case with &' and @' as well to access global function and global array respectively?
      No. ' is the name of the variable, and because you don't declare it, it is global, and because the current package is main, they are &main::' and @main::' respectively
      $ perl -le"print \@', \@{qq!main::'!}" ARRAY(0x979ff4)ARRAY(0x979ff4) $ perl -le"print &'" Undefined subroutine &main::' called at -e line 1.