in reply to Pronoun Programming

It makes sense to me!

In Perl, 'it' is spelled '$_', and is an important part of the design of Perl 5, growing more important in Perl 6, and in the Perl 6 pieces that were back-ported into perl 5.10. Remember, Larry Wall is a linguist by training, and understands the value of pronouns. From Perl 6 and Parrot Essentials:

$_ is always the current topic (think "topic of conversation"), so the process of aliasing a variable to $_ is known as topicalization.

Consider this expression:

$entirely{TOO}[$long]{$var} = 42 if $entirely{TOO}[$long]{$var} < 5;
In Perl 5, the idiom for briefly topicalizing a variable is the single-item for statement:
for ( $entirely{TOO}[$long]{$var} ) { $_ = 42 if $_ < 5; }
This is slightly jarring at first; we expect a for loop to, well, loop! I had to use the idiom a few times to get used to it.

If you need multiple (yet discrete and update-able) pronouns at the same time, the Data::Alias module can create them. ($his and $hers?)

Unfortunately, none of this can help with your specific example. The delete function, like exists, does not actually operate on a hash value; it is more of a method call on the hash "object" with the key as a parameter. In fact, I believe that in Perl 6, delete %myhash{$mykey} is really just syntactic sugar for %myhash.delete($mykey).

You can look at it this way: nearly everything you do with %myhash{$mykey} involves retrieving the value stored in the $mykey bucket, doing something with it, and possibly storing it back in its bucket. The major exceptions are delete and exists, which deal with destroying or verifying the bucket *itself*. The fact that we use the same %myhash{$mykey} syntax for everything is just for convenience; the cases are quite different under the hood. An alias that allows deletion of the alias-forming-key may be too much to expect, but I agree that it would be convenient.

Replies are listed 'Best First'.
Re^2: Pronoun Programming
by girarde (Hermit) on Feb 05, 2008 at 21:14 UTC
    This is slightly jarring at first; we expect a for loop to, well, loop! I had to use the idiom a few times to get used to it.

    For the case that for(foo) is an alias for 'for the case that foo is true', though, it makes perfect sense, and a for loop with nothing to iterate over is such a case. :-)