Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^6: RFC: Tutorial: use strict; now what!?

by educated_foo (Vicar)
on Feb 09, 2012 at 17:10 UTC ( #952788=note: print w/ replies, xml ) Need Help??


in reply to Re^5: RFC: Tutorial: use strict; now what!?
in thread RFC: Tutorial: use strict; now what!?

Are you running exactly that program? What version of Perl? This is what I get:

$ cat foo2.pl $foo = 23; $soft = 'foo'; $hard = \$foo; print "soft=$$soft, hard=$$hard\n"; $ perl foo2.pl soft=23, hard=23 $ perl -v This is perl, v5.10.1 (*) built for i686-cygwin-thread-multi-64int


Comment on Re^6: RFC: Tutorial: use strict; now what!?
Download Code
Re^7: RFC: Tutorial: use strict; now what!?
by tangent (Curate) on Feb 09, 2012 at 17:29 UTC
    I did change it slightly by adding my (couldn't help myself)
    user$ cat foo2.pl my $foo = 23; my $soft = 'foo'; # soft reference my $hard = \$foo; # hard reference print "soft=$$soft, hard=$$hard\n"; user$ perl foo2.pl soft=, hard=23 user$ perl -v This is perl 5, version 14, subversion 1 (v5.14.1) built for darwin-2level user$ cat foo3.pl $foo = 23; $soft = 'foo'; # soft reference $hard = \$foo; # hard reference print "soft=$$soft, hard=$$hard\n"; user$ perl foo3.pl soft=23, hard=23
    I think I've learnt something about 'my' too!
      That's your problem: my makes a variable lexical, and symbolic references only work with dynamic/global variables. BTW, this is also why mixing eval STRING with lexicals is problematic:
      foobar:perl/blead% perl -le '$y="print \$x"; $z=sub { my $x=23; $y}; e +val $z->()' foobar:perl/blead% perl -le '$y="print \$x"; $z=sub { $x=23; $y}; eval + $z->()' 23

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (8)
As of 2014-12-23 00:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (133 votes), past polls