Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Add numbers row by row

by toolic (Bishop)
on Oct 25, 2013 at 14:05 UTC ( [id://1059674]=note: print w/replies, xml ) Need Help??


in reply to Add numbers row by row

use warnings; use strict; my $tot = 0; while (<DATA>) { my ($num, $date) = split; $tot += $num; printf "%-5d %s\n", $tot, $date; } __DATA__ 1 2005-01-16 6 2005-01-28 1 2005-01-31 2 2005-02-01 2 2005-02-02 1 2005-02-05

Replies are listed 'Best First'.
Re^2: Add numbers row by row
by epimenidecretese (Acolyte) on Oct 25, 2013 at 14:20 UTC
    Thank you very much! Works great. Where could I learn something about this string?
    printf "%-5d %s\n", $tot, $date;
    I don't really understand what's going on.

    One of Crete's own prophets has said it: 'Cretans are always liars, evil brutes, lazy gluttons'.
    He has surely told the truth.

      You're welcome.
      Where could I learn something about this string?

      In a variety of places:

      • The "Function Nodelet", which is on the right side near the bottom of the page of my browser here at the Monastery, has a link to the printf docs. I'm not sure if this nodelet is enabled by default.
      • The official documentation is online: printf
      • And it is also at your command prompt: perldoc -f printf
      > Where could I learn something about this string?

      You either type "perldoc -fprintf" or sprintf into your console ...

      ... or you check the online docs at http://perldoc.perl.org (but beware of the Perl version)

      It's also searchable per "duckduckgo: perl printf" or "google: perl printf" or other search machines...

      Cheers Rolf

      ( addicted to the Perl Programming Language)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1059674]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2024-04-19 08:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found