Hi supriyoch_2008,

A Perl programmer developing a script without use strict is a bit like a trapeze artist practising a new trick without a safety net. In other words, it’s a Bad Idea (unless you enjoy all-night debugging sessions). But it’s your call.

However, I think you may have some misconceptions about what strict does:

I have noticed that "use strict;" sometimes does not give me the correct result from my script and the cmd shows a large number of warnings. Without the "use strict;" line in my script, I often get the desired result.

This is simply not possible! First, use strict never issues warnings, it generates errors which cause the script to abort immediately they occur. Second, if the script runs without errors, then the presence of use strict does not change the way it runs in any way.

use strict is actually three pragmata rolled into one:

  1. use strict 'refs';

    This prevents you from using symbolic references, and since you probably don’t use them anyway, it won’t have much impact on your code.

  2. use strict 'subs';

    Consider the difference between these snippets:

    18:18 >perl -E "sub foo { return 'bar'; } $y = foo; say $y;" bar 18:19 >perl -E "$y = foo; sub foo { return 'bar'; } say $y;" foo 18:20 >

    In the second, “foo” is treated as a string, not a subroutine name, so the output is not what you wanted. use strict 'subs' prevents this by forcing you to either declare your subroutines before calling them, or call them explicitly with parentheses. This is a Good Thing.

  3. use strict 'vars';

    This is the one that makes you declare each variable with my (or our) the first time it is used. More typing? Sure, but think how much debugging time it will save you down the track when you have a variable named opensesame which you later write as openseseme by mistake!

See strict and then recite The strictures, according to Seuss as needed. :-)

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


In reply to Re^3: How can one input a textfile from desktop just created? by Athanasius
in thread How can one input a textfile from desktop just created? by supriyoch_2008

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.