Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
chomp (my @lines = <DATA>);

Who knows how that works, but it does. It's a perl idiom you need to know.

Yes, it’s a useful idiom — but surely not so mysterious?

  1. my @lines =
    Declares a lexical array variable and initialises it (with a list of array elements).

  2. @lines = <DATA>
    The LHS (left-hand side) of the assignment is an array, which gives list context to the expression on the RHS. When the readline or “diamond” operator <...> is placed in list context, it “reads until end-of-file is reached and returns a list of lines.” Lines are defined as the text between successive input record separators. The input record separator, stored in $/, “is newline by default.” See readline and General Variables in perlvar.

  3. chomp(...);
    When chomp is given a list, it chomps (removes the input record separator from) each element in the list.

That wasn’t really so hard, was it? ;-)

Avoid writing $_ in your code.

Yes, avoid writing $_ explicitly where possible. But be aware that an explicit $_ is often needed; for example:

  • my @doubles = map { $_ * 2 } @numbers;

  • $couples{$_} eq 'Betty' && print for keys %couples;  # Find Betty's husband

Hope that helps,

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


In reply to Re^2: Using HTML Template to fill a 2-dimensional table by Athanasius
in thread Using HTML Template to fill a 2-dimensional table by jms53

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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (9)
    As of 2014-08-20 21:06 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (124 votes), past polls