Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Re: Re: Re: A Perl aptitude test

by marinersk (Chaplain)
on May 15, 2003 at 15:40 UTC ( #258410=note: print w/ replies, xml ) Need Help??


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

In my extremely limited experience with Perl, I've only run into one place where I couldn't use strict; I had a module that was tracking multiple file locks using flock() and I was storing the various file handles in a hash. When I tried to close the files (and thus release flock()'s lock) I got an error about "using string substitution for symbolic table entries under strict" or some such thing. So I commented out the use strict; line and documented why, and forced that set of functions into its own module, never to be mingled with others.

So, I suppose, implicit in this story is that, for now, I wouldn't not use strict; unless it was required.


Comment on Re: Re: Re: Re: A Perl aptitude test
Select or Download Code
Re: Re: Re: Re: Re: A Perl aptitude test
by BrowserUk (Pope) on May 15, 2003 at 16:17 UTC

    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
      I am saddened to see I never got around to thanking you for this post.

      As a consequence of your reply, I learned that strict was lexically scoped, as well as the syntax for how to release its iron grip, as well as the idea that one could reduce only pertinent portion of its iron grip and the synxtax thereto, resulting in this snippet which was no longer relegated to its "quarantine module":

      # If it's our last lock, release it. if (!$lckcnt) { # It's our last lock. Release the lock token file. my $lckfnm = &_getLockFilename($filfnm); { # Must disable warnings and strict for this no warnings; no strict; close $Lckhan{$KEY_LCKHAN}{$filfnm}; } }

      So, as many times before, thanks for having taken the time to write this -- OMG -- ten years ago.

        I'm glad you found it useful :)

        But, I still don't get your problem with using file handles stored in hash elements with close when strict and warnings are enabled?

        C:\test>perl -mstrict -wE" open $f{w},'<words.txt'; print ~~readline($ +f{w}); close $f{w}" aa

        I can never work out how to use them with the angle bracket (<>) form of readline, but no problem with open or close.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2014-11-22 09:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (121 votes), past polls