Ryan Frantz wrote: > Perlers, Hello,
> 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. > > --begin script-- > > #!/usr/bin/perl > > use strict; > use warnings; > > my $missing_claims = "missing_claims.txt"; > my $ih_file = "ih.new"; > my $output = "matches.log"; > > my @claims; > open(MISSING, $missing_claims) or die "Unable to open > $missing_claims:$!\n"; ^^ ** > chomp(@claims = <MISSING>); > 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"; ^ * Your first die statement includes the $! variable, the other two should include it as well. > 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; The only problem I can see is that $claim may contain regular expression meta-characters that may cause the match to fail. You should probably use quotemeta. my @matched = grep /\Q$claim/, @ih; > if ( @matched ){ > print LOG "@matched"; Do you really want to enclose @matched inside quotes? perldoc -q "Why do I get weird spaces when I print an array of lines" > #print "@matched"; > } > # my $num_matched = @matched; > # print "Claim matched: $num_matched: @matched\n"; > } > > close LOG; John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>