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

In reply to Re: Re: Re: Re: Re: A Perl aptitude test by BrowserUk
in thread A Perl aptitude test by Jonathan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.