Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Reference assessment techniques and how they fail

by Jenda (Abbot)
on Feb 18, 2008 at 13:36 UTC ( [id://668537]=note: print w/replies, xml ) Need Help??


in reply to Reference assessment techniques and how they fail

If anyone blesses a reference to package '0', he deserves what he gets. It's if (ref $r) { and if (blessed $r) { for me. Few people bother with writing for(my $i = $[; $i <= $#arr; $i++) and changing the index of the first element in an array is a more sane thing that blessing into a crazily named package into which you'd have problems adding methods.

Thanks for the node though, the rest was very interesting!

Replies are listed 'Best First'.
Re^2: Reference assessment techniques and how they fail ($[)
by lodin (Hermit) on Apr 07, 2008 at 12:22 UTC

    Few people bother with writing for(my $i = $[; $i <= $#arr; $i++)

    In Perl 5 $[ is a lexical compiler directive, so you don't have to worry about other users messing with your code through $[.

    lodin

      Note that, unlike other compile-time directives (such as strict), assignment to $[ can be seen from outer lexical scopes in the same file. However, you can use local() on it to strictly bound its value to a lexical block.
             from perldoc perlvar

      So I don't have to worry that someone will change mine $[ from within a different file that I used, but I still might run into problems if someone fiddles with $[ somewhere above my code in the same file.

      @a = (0,1,2,3,4,5); sub pr { print "sub \$a[2]=$a[2]\n"; } print "\$a[2]=$a[2]\n"; pr; { $[ = 1; print "\$a[2]=$a[2]\n"; pr; } print "\$a[2]=$a[2]\n"; pr;

      I refuse to worry anyway.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-19 23:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found