Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
This is really more a question of aesthetics and coding practice than whether it works or not. Should "my" just be thrown into the middle of the code, where it's nearest to where the variable is needed, or stated at the top, where it's easier to see all your variables and where the "my" doesn't cause things to potentially not line up? For instance, if you were doing something like this:

my $saved = pop @array; print "Now we have @array and I have saved $saved\n"; $saved = pop @array; print "Now we have @array and I have saved $saved\n";

Personally, I like declaring at the top, especially if a variable is used several times, but others prefer declaring at the point at which the variable is first used. I still haven't figured out which method is really superior.

Here's a few more samples of interesting things you can do with arrays:

Using the standard output variable instead of declaring a new one:

$_ = pop @arr; print "Value popped is $_\n";

Cycling through the array, method 1 (each value is put in standard output variable in turn):
print "Value is $_\n" for @arr;

Cycling through the array, method 2 ($# represents the subscript of the last item in the array):
print "Value is $arr[$_]\n" for 0..$#arr;

In reply to Re: Is it ok to assign a popped value to a variable as shown. by TJPride
in thread Is it ok to assign a popped value to a variable as shown. by perl514

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 avoiding work at the Monastery: (5)
    As of 2018-02-19 20:47 GMT
    Find Nodes?
      Voting Booth?
      When it is dark outside I am happiest to see ...

      Results (266 votes). Check out past polls.