Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

(bwana147) Using printf

by bwana147 (Pilgrim)
on Jul 02, 2001 at 14:32 UTC ( [id://93184]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Using printf

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://93184]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.