Near the beginning of the script I have all warnings switched on:

use warnings;

The warnings pragma is lexically scoped and so affects the entire script.

When I first started to test Storable with coderefs, my code looked like this:

use Storable qw{nstore retrieve}; $Storable::Deparse = 1; $Storable::Eval = 1;

Perl emitted a warning that each of those variables had only been used once and this possibly indicated an error in my code. I knew there wasn't an error and I didn't want this warning to be constantly displayed. I could have switched the warning off like this

use Storable qw{nstore retrieve}; no warnings q{once}; $Storable::Deparse = 1; $Storable::Eval = 1;

but that would have turned off the warning for the entire script: maybe later in the script there was a real error which now wouldn't be reported.

By using a block I constrain the scope of the warning suppression to just that block. Furthermore, it also highlights what has been done. The following is equivalent but uses more code and is less obvious:

use Storable qw{nstore retrieve}; no warnings q{once}; $Storable::Deparse = 1; $Storable::Eval = 1; use warnings q{once};

Compare that with the block form:

use Storable qw{nstore retrieve}; { no warnings qw{once}; $Storable::Deparse = 1; $Storable::Eval = 1; }

-- Ken


In reply to Re^3: Creating a Moose object and serializing it by kcott
in thread Creating a Moose object and serializing it by daverave

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.