Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

we're really guessing at what you are trying to do, so in that spirit maybe here's a real life example that has enough stuff in it to be useful on a few fronts...

test file
#ls -la > test.txt ... abreviated

-rw-r--r--  1 OQ91   Domain Users   273532 Sep 25 15:29 spy.csv.bak
-rw-r--r--  1 OQ91   Domain Users    14704 Jan  8 12:08 spy.sdf
-rw-r--r--  1 OQ91   Domain Users     4329 Oct 17 10:28 spy.sdf.bak
-rwxr-xr-x  1 OQ91   Domain Users  1196465 Sep 26 03:36 spywork.ods
-rw-r--r--  1 OQ91   Domain Users   312739 Jan  8 09:40 spyx.csv
-rwxrwxr-x  1 OQ91   Domain Users     4875 Dec 26 22:05
-rwxr-xr-x  1 OQ91   Domain Users     2396 Oct 25 09:57
-rwxr-xr-x  1 OQ91   Domain Users     3375 Oct 29 10:27
-rwxr-xr-x  1 OQ91   Domain Users     3811 Oct 29 07:52
-rwxr-xr-x  1 OQ91   Domain Users     3809 Nov  8 11:06
-rwxr-xr-x  1 OQ91   Domain Users 77687808 Sep 26 03:46 Taylor_Book_08.xls
-rw-r--r--  1 OQ91   Domain Users     9095 Dec 26 22:14
-rw-r--r--  1 OQ91   Domain Users     4350 Nov  7 01:07
-rw-r--r--  1 OQ91   Domain Users     4424 Nov  7 11:57
-rw-r--r--  1 OQ91   Domain Users     8630 Nov  7 13:57
-rw-r--r--  1 OQ91   Domain Users     9039 Nov  8 08:59
-rw-r--r--  1 OQ91   Domain Users     9156 Dec 26 22:10
-rw-r--r--  1 OQ91   Domain Users    46987 Dec  4 13:25 zzz.out
$ cat test.txt | perl -l -n -e 'BEGIN {$x="OQ91";$linecount=0;$sum=0;} if((split)[2]==$x){$linecount++ ;$sum += (split)[5]; printf "%s\t %s\t\t %s\n",(split)[2],(split)[5],(split)[9]} ; END {printf "linecount: %d  Sum: %d",$linecount,$sum}'

Here's some output... abreviated

OQ91     312739          spyx.csv
OQ91     4875  
OQ91     2396  
OQ91     3375  
OQ91     3811  
OQ91     3809  
OQ91     77687808                Taylor_Book_08.xls
OQ91     9095  
OQ91     4350  
OQ91     4424  
OQ91     8630  
OQ91     9039  
OQ91     9156  
OQ91     46987           zzz.out
linecount: 61  Sum: 88200728

sums the 5th column if the tests are true, counts the lines... prints the 2nd, 5th and 9th columns, AND it's a one liner...

In reply to Re^2: While Loops by tbone654
in thread While Loops by Anonymous Monk

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 the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others romping around the Monastery: (11)
    As of 2015-12-01 15:17 GMT
    Find Nodes?
      Voting Booth?

      My keyboard shows this many letters:

      Results (13 votes), past polls