Yes, two handles at once, like so:
open(DB_RESULT,">/path/to/result/db/file");
open(DB_SRC,"/path/to/source/db/file");
while (<DB_SRC>){
if($_ ~= /$user/){
my @user_fields = split /:/,$_;
$user_fields[2] = $user_fields[2] + $newtraffic;
my $newline = $user_fields[0].':'.$user_fields[1].':'.$user_fields
+[2];
print DB_RESULT, $newline;
} else {
print DB_RESULT, $_;
}
}
close(DB_SRC);
close(DB_RESULT);
my $result = `mv /path/to/result/db/file /path/to/source/db/file`;
There may be some slick way to do this with only one file open overwriting only the line you are concerned with, but it is not apparent to me at this late hour. And generally I am of the mind that it is more important to ensure that a program works than that it is fast or fancy.
if( $lal && $lol ) { $life++; }
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.