I have a text file generated with file names that have already printed. I am trying to loop through the .txt file and if I see a file name, don't do anything. However, with the way I have it written, if ANY file shows up, nothing prints (print to another .dat file). How do I control the loop through the PARTS text file? Here's my code snip:
$partlist = "D:\\scripts\\partlist.txt";
#get the parts that have already been printed
open(PARTS, $partlist) || die "Can't open file: $!";
@PARTS= <PARTS>;
close(PARTS);
#set counter
$found = 0;
foreach $PARTS(@PARTS) {
if ($PARTS == $ordnum) {
$found=1;
}}
if ($found eq 0){
$verifile = $outbox.$ordnum.".dat";
##Open output file to write to
open(OUTPUT_FILE, ">>$verifile")||die "Can't open file: $!";
print OUTPUT_FILE $these.$happy.$variables
close OUTPUT_FILE;
else
{
#nothing
}
I know my logic is a little off, but can't seem to iron it out. Any thoughts?
update:
$partlist contains, for example, the text printfileA, I am going out to a DB getting an order number and then bringing back in with a hash... if the result of the order is printfileA.dat then it should not print since it's already been printed as indicated by $partlist. However, if my DB results show printfileA.dat and then printfileB.dat, printfileB.dat never gets created because the script stopped once it saw printfileA.dat. Sorry if I haven't been clear enough.
-Hu
Edit: g0n - code tags
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.