#3 indicates a position where a filehandle was used for an open and never used again, not even to check return value on a close.

close will never fail, cause all we want to do is create the file.

It adds all of a dozen characters

But that's a dozen of characters of unnecessary code. For just one line of code! I'd have useless code all over the place. Code that can do nothing but introduce errors, since it doesn't serve any function.

and leaves the warnings valid for any time I had opened multiple files, and then accidentally used one of the file descriptors twice in a row instead of using the one I intended.

No. Since you believe in closing everything explicitly, the warning won't help you there.

# $fh1 $fh2 # ---- ---- open(my $fh1, '>', $file1) or die; # 1 open(my $fh2, '>', $file2) or die; # 1 for (@data) { # print $fh1 "$_\n"; # 1 print $fh1 "$_\n"; # Oops # 1 } # close($fh1); # 1 close($fh2); # 1 # ---- ---- # 4 2 -> no warnings

Furthermore, autodie is a great module for testing errors on close, and it doesn't reference the file handle explicitly.

I'm not sure why putting your locks in your constructor

No, the constructor obtains the lock. The object is the lock.

I would not personally use constructor methods named in such a way that they can be easily mistaken for procedures

You've never used threads? And constructors are routinely called names other than new.

I'm not sure why [RAII] is substantially better [...] explicitly locking the object until it passes out of scope.

To properly release the lock when an exception occurs or when return is used more than once.

but I'd argue that this is exactly why I want a warning on code that looks like that.

I'd rather avoid doing away with exceptions, I'd rather my code doesn't throw spurious warnings, and I'd rather not have to us no warnings; all over the place. That's why it's better checked by a linter or until turned on explicitly (meaning -v and use warnings; wouldn't enable it).

You've hidden functionality inside a destructor-only event that is going to trigger many lines of code away from when you prepped it. I want a warning if someone does that.

You say deallocation of resources on block exit worthy of a warning? Every single variable in Perl does that!


In reply to Re^5: Warnings on unused variables? by ikegami
in thread Warnings on unused variables? by AZed

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.