hello guys,
i have a hard time looking @ what's wrong with this script.
is it really right to open two files simultaneously and assign variables?
in temp.txt(output), every value of $check1 (rep. by 300)in every line is the same as the value of $check1 on the first line of file1.txt, like...
222-3344,joe,300,200,100,increase
222-3344,joe,300,150,150,increase
222-3344,joe,300,550,250,decrease
here's the my kiddy script:
#!/usr/bin/perl -w
#file1 format: name|phone|check amount this mo.
#file2 format: name|phone|check amount last mo.
open(F1,"file1.txt") ||
die "cannot open $infilename for reading: $!";
open(F2,"file2.txt") ||
die "cannot open $infilename for reading: $!";
open(F3,">temp.txt") ||
die "cannot create $outfilename: $!";
while (<F1>) {
($name,$phone,$check1) = split(/\|/);
while (<F2>) {
($name,$phone,$check2) = split(/\|/);
$change = $check1 - $check2;
if ($check2 > $check1) {
$stat = "decrease";
}
else {
$stat = "increase";
}
$_ = join ',', ("$phone","$name","$check1","$check2","$change","$stat"
+);
print F3 "$_\n";
}
}
close (F1);
close (F2);
close (F3);
Edited 2002-04-04 by mirod: changed title
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.