- Closed your files when you were done with them.;
- Declared your variables (required under strict and intensely recommended for a huge list of reasons)
#!/usr/bin/perl
use strict;
my %csga = ();
my $moyr="12/2014";
$,="\t";
open(IN,"<COS_SGA_xref.txt");
while(<IN>) {
chop;
@_ = split(/\t/);
$csga{$_[0]}=$_[1];
}
close IN;
open(IN,"<cc.txt");
open(OUT,">new_cc.txt");
for(my $i=0;$i<9;$i++) {$_=<IN>;}
my ($mo,$yr)=@_ = split(/\//,$moyr);
while(<IN>) {
chop;
@_ = split(/\t/);
my $created=pop(@_);
my ($mocr,$day,$yrcr)=@_ = split(/\//,$created);
if($yrcr.$mocr >= $yr.$mo) {
my $cc=$_[1];
$cc =~ y/C_//d;
splice(@_,3,1);
shift(@_);
print OUT $created,@_,$csga{$cc};
print OUT "\n";
}
}
close IN;
close OUT;
__END__
And the results:
D:\PerlMonks>test2.pl
D:\PerlMonks>
It created an empty output file called new_cc.txt. I presume that's because I did not have the input file COS_SGA_xref.txt.
I'm afraid additional debugging will be all guesswork unless you can provide sample input data.
At a guess, however, your problem is one of two things:
- Since you didn't close IN, your attempt to open it again failed.
- If you would check for errors on open, you could catch such things.
- You only write output if this statement is true: if($yrcr.$mocr >= $yr.$mo). Maybe it never is?
- A print statement right before the if could reveal the issue.
- 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.