Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
This example does not declare variables in the beginning of the script: that is, these variables are only visible inside the scope of the sub CheckAllPairs. This is called "lexical" scoping, and extends from a "my" declaration to the end of the scope of the my. Perl also has global variables, which you usually use the "our" declarator to introduce, but as a rule of thumb lexicals are better for most purposes.

Using strict is almost always a good idea, yes. Having so many variables like in that example looks like a lot, but maybe it's warranted by what the code is doing. If you want to declare several lexicals all at once rather than on separate lines, you can do it the following way, but it's mostly a stylistic thing:

my ($subj_num, $region, $region1, $region2, $time); # put as many as y +ou like here my ($abs_time, $max_peak_time) = (50, 2050) # you can initiali +ze multiple vars like this.

In reply to Re: Declaring a Variable [for BEGINNERS] by gaal
in thread Declaring a Variable [for BEGINNERS] by brusimm

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others imbibing at the Monastery: (7)
    As of 2018-01-18 12:37 GMT
    Find Nodes?
      Voting Booth?
      How did you see in the new year?

      Results (211 votes). Check out past polls.