Other mighty monks have already said all that there is to say. I'll just add some comments about legibility and nice formatting.

The printf function takes a format as first argument, and then a list of values. The first argument being special, I'm fond of using the => operator to let it stand out from the rest:

printf "%18s %18s %18s\n" => $ip_date_time[$i]{ip}, $ip_date_time[$i]{date}, $ip_date_time[$i]{time};

Now, we use three times the $ip_data_time[$i]: if you translate that into English, it reads: "print out the ip of the ith element of $ip_date_time, the date of the ith element of $ip_date_time and the time of the ith element of $ip_date_time". I guess it would sound more natural to say "print out the ip, date and time of the ith element of $ip_date_time". Several ways to say that in perl:

# a map print "%18s %18s %18s\n" => map {$ip_date_time[$i]{$_}} qw/ip date tim +e/; # a hash slice print "%18s %18s %18s\n" => @{$ip_date_time[$i]}{qw/ip date time/};

Voilà, that was just my €0.02.

--bwana147


In reply to (bwana147) Using printf by bwana147
in thread Using printf by nysus

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.