Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hi, i have a litle script that opens a txt doc, and looks into each row, and counts the files. It then prints out each rows name, and the count, and it that works fine. but i want to total the count of all the rows and give me the total at the bottom. I tired using
push (@total, $fileslistcount); $total = @total;)
to push all the arrays into one sum, but its adding up the total rows of the txt doc, not the sum total of the file counts. how do add the totals to one array and save it so it only prints out once after the loop?
chdir($desktop_dir) or mail ($to = $dllist, $from = $dllist, $subject= + "ERROR $desktop_dir $!", $body ="ERROR $desktop_dir $!" ); (@listofdir) = glob "*txt"; foreach my $file (@listofdir){ chdir($desktop_dir) or mail ($to = $dllist, $from = $dllist, $subject= + "ERROR $desktop_dir $!", $body ="ERROR $desktop_dir $!" ); open(my $fh, '<:encoding(UTF-8)', $file)or mail ($to = $dllist, $from += $dllist, $subject= "error opening $file $!", $body ="ERROR opening + to $file $!" ); open FILE, ">> $mastercount" or mail ($to = $dllist, $from = $dllist, + $subject= "ERROR opening $mastercount", $body ="ERROR opening $mast +ercount" ); while (my $row = <$fh>) {#2 chomp $row; foreach ($row) { chdir ($row)or mail ($to = $dllist, $from = $dllist, $subject= + "error opening $row", $body ="ERROR opening to $row" ); if ( -e "Thumbs.db") { unlink ("Thumbs.db") or print "thumbs.db $!\n"; }; (@fileslist) = glob "*{jpg,gif,psd,png,tif,tiff}"; my $fileslistcount = @fileslist; push (@total, $fileslistcount); $total = @total; if ($fileslistcount > 0){ print "total files in $row:$fileslistcount\n"; } else { # print "not enought files to count\n"; } } } print "total files in $total\n"; }; close FILE;

In reply to adding to an array from foreach loop by flieckster

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-03-28 20:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found