> -----Original Message----- > From: Ryan Frantz > Sent: Monday, August 22, 2005 11:32 AM > To: Beginners Perl > Subject: I/O: Can't Output to a File > > Perlers, > > I'm stumped; I have a script that should output to a file but it > doesn't. The file is created, but it's empty after the script > completes. To be sure I was getting some sort of output, I had the > script write to the terminal and all was well. The odd thing, however, > is that I still can't redirect it into a file! Any clues? My script is > below. >
Scratch that! What I sent to the list was the (recently) modified version that I ran as I sent this to the list. I think I found the problem: > --begin script-- > > #!/usr/bin/perl > > use strict; > use warnings; > > my $missing_claims = "missing_claims.txt"; > my $ih_file = "ih.new"; > my $output = "matches.log"; > This block used to include: > my @claims; > open(MISSING, $missing_claims) or die "Unable to open > $missing_claims:$!\n"; --> while (<MISSING>) { > chomp(@claims = <MISSING>); --> } Don't ask me why I did that... I have no idea. However, can anyone explain why this may have caused a problem? > close MISSING; > > my @ih; > open(IH, $ih_file) or die "Unable to open $ih_file:!\n"; > @ih = <IH>; > close IH; > > open(LOG, ">>$output") or die "Unable to open $output:!\n"; > > print LOG "------------ ------ ------- ----------\n"; > print LOG " Image Name Loc. Removed New Loc. \n"; > print LOG "------------ ------ ------- ----------\n"; > > foreach my $claim (@claims) { > # print "CLAIM: $claim\n"; > my @matched = grep /$claim/, @ih; > if ( @matched ){ > print LOG "@matched"; > #print "@matched"; > } > # my $num_matched = @matched; > # print "Claim matched: $num_matched: @matched\n"; > } > > close LOG; > > --end script-- > > ry > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > <http://learn.perl.org/> <http://learn.perl.org/first-response> > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>