http://www.perlmonks.org?node_id=258429


in reply to Re: Re: Re: Re: A Perl aptitude test
in thread A Perl aptitude test

I'm probably misunderstanding your description as I couldn't create the error you describe, but maybe you were using an earlier version of Perl?

use strict; open FH, '<', 'test1.dat' or die $!; my %h; $h{FH}=FH; flock( $h{FH}, 2); close $h{FH}

That said, the only critisism of your approach I would have, and it's only from the "if your going to use strict, use it everywhere possible" point of view, is that as strict is lexically scoped, you can usually get away with something like

.... { no strict 'refs'; # do the thing that conflicts with strict. } ....

Which retains as many of the benefits of strict as possible for as much of the code as possible and adds an element of self documentation, which you could always add to if necessary. In your case, it would also remove the need for a seperate module if that meant an abitrary split in codebase.

To date, I haven't found a single time when I've wanted to drop strict, even at very localised level. Perhaps because every program I write starts life as a template that includes it. Maybe because I've never been a shell programmer and never used Perl before v5.6. Whatever the reason, I never even find myself going out of my way to avoid dropping it. The issue just never seems to come up. Then again, I think I've only used eval 2 or 3 times.

Maybe there is a whole world of simple, elegant solutions to difficult problems that I'm missing out on, but for now I'm happy in my ignorance of them:)

All of that said. If I ever encounter a situation where I needed to drop strict (locally), I wouldn't hesitate to do so if it made sense, especially if it avoided a convoluted work-around.

In essence, I agree with your answer:)


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller