Berkeley CSUA MOTD:1998:January:06 Tuesday
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
1998/1/6 [Computer/SW/Languages/Perl] UID:49806 Activity:nil
1/6     If anyone with any Perl 5.004 fu can explain the following behavior
        coherently, I'd be enlightened
        1) why are the following two different:
                my($result1) = `cp --help 2>&1`;  #problem! scoping?
                   $result2  = `cp --help 2>&1`;  #right behavior
        2) why are the following two different:
                subs HEY {};
                my($sub1) = 'HEY';   #problem! global scoping problem?
                   $sub2  = 'HEY';   #no problem
                &$sub1;
                &$sub2;
        3) by inserting my($_), I get an error that is far remote from
           what Perl really claims to have. Another scoping problem?
1998/1/6 [Computer/SW/Languages/Perl] UID:49807 Activity:nil
1/6     If anyone with any Perl 5.004 fu can explain the following behavior
        coherently, I'd be enlightened. The file is located in
        ~god/Pub/perl.bugs
        \_ 1.  The first evaluates the backquote expression in list context
               and stores the first element of the result in $result1.  The
               second evaluates the backquote expression in scalar context
               and stores the entire result, as a string, in $result2.  It
               has nothing to do with your use of "my"; you can (and should)
               rewrite the second as
                  my $result2 = `cp --help 2>&1`;
               See "perldoc perlsub" for more information.
           2.  Both of your examples work fine for me.  Could you elaborate
               on what goes wrong when you try them?
           3.  You can't declare $_ with my.  This is a special case in perl
               which may change sometime; it's mentioned in "perldoc perlsub".
               For now, use local instead of my for $_.
Berkeley CSUA MOTD:1998:January:06 Tuesday