[JOB] Perl Software Developer and Database programmer

Dominic Mitchell dom at happygiraffe.net
Wed Feb 22 13:10:54 GMT 2006


On Wed, Feb 22, 2006 at 12:36:33PM +0000, Lusercop wrote:
> On Wed, Feb 22, 2006 at 12:19:09PM +0000, Andy Armstrong wrote:
> > On 22 Feb 2006, at 12:07, Lusercop wrote:
> >> this thread. (and given that you can simulate the effects of local with a
> >> more explicit set of mys, in a much clearer way, then this is also true).
> > What simulation of local are you advocating and why?
> 
> {
>    my $newdollarslash = "whatIwant";
>    my $savdollarslash = $/;
>    $/ = $newdollarslash;
> 
>    dostuffwithappropriatecalls();
> 
>    $/ = $savdollarslash;
> }
> 
> obviously.
> 
> this is the equivalent of:
> 
> {
>    local $/;
> 
>    my $newdollarslash = "whatIwant";
>    $/ = $newdollarslash;
> 
>    dostuffwithappropriatecalls();
> }
> 
> Why? because it's clear that you're saving the value and restoring it. For
> those in the thread that didn't know that this was what local did, that's
> what it does. If the scope is quite long (then you should be splitting it
> into separate functions ...) then you are explicitly restoring the value
> back. I prefer this, stylewise.

What about eval{}?  If you throw an exception, the old value won't be
restored.

-Dom


More information about the london.pm mailing list