| Ryan Frantz 2005-08-22, 6:58 pm |
|
> -----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
>=20
> Perlers,
>=20
> 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:
=20
> --begin script--
>=20
> #!/usr/bin/perl
>=20
> use strict;
> use warnings;
>=20
> my $missing_claims =3D "missing_claims.txt";
> my $ih_file =3D "ih.new";
> my $output =3D "matches.log";
>=20
This block used to include:
> my @claims;
> open(MISSING, $missing_claims) or die "Unable to open
> $missing_claims:$!\n";
--> while (<MISSING> ) {
> chomp(@claims =3D <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;
>=20
> my @ih;
> open(IH, $ih_file) or die "Unable to open $ih_file:!\n";
> @ih =3D <IH>;
> close IH;
>=20
> open(LOG, ">>$output") or die "Unable to open $output:!\n";
>=20
> print LOG "------------ ------ ------- ----------\n";
> print LOG " Image Name Loc. Removed New Loc. \n";
> print LOG "------------ ------ ------- ----------\n";
>=20
> foreach my $claim (@claims) {
> # print "CLAIM: $claim\n";
> my @matched =3D grep /$claim/, @ih;
> if ( @matched ){
> print LOG "@matched";
> #print "@matched";
> }
> # my $num_matched =3D @matched;
> # print "Claim matched: $num_matched: @matched\n";
> }
>=20
> close LOG;
>=20
> --end script--
>=20
> ry
>=20
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>=20
|