mercuryshipz has asked for the wisdom of the Perl Monks concerning the following question:
Use of uninitialized value in substitution (s///) at sn8.pl line 51. Use of uninitialized value in string gt at sn8.pl line 52. -1
#!/usr/bin/perl # use strict; use warnings; use List::Util q{first}; sub search_phrase{ my @array; my ( $inFile, @phrases ) = @_; my $lastPhrase = $phrases[ -1 ]; open my $inFH, q{<}, $inFile or die qq{open: $inFile: $!\n}; my @lines = <$inFH>; close $inFH or die qq{close: $!\n}; foreach my $phrase ( @phrases ) { my $rxPhrase = qr{\Q$phrase\E}; my $lineNo = first { $lines[ $_ ] =~ $rxPhrase } 0 .. $#lines; unless ( defined $lineNo ) { #print "-1"; # print qq{$phrase: not found in sequence\n}; next; } print "" if ($lines[ $lineNo ] =~ m{\Q$lastPhrase\E\s*(\d*)}); push (@array,$1); $lineNo ++; splice @lines, 0, $lineNo; } return (@array); } my $file_n = "test2.txt"; my $phrase1 = "total rejected rows:"; my $phrase2 = "total rejected recors:"; my $phrase3 = "rejectb:"; my $phrase4 = "total rejected rows:"; my @newarray=search_phrase($file_n, $phrase1, $phrase2, $phrase3, $phr +ase4); my $count=($#newarray); $newarray[$count]=~ s/\s+//g; if ((($#newarray+1)>=1) && ($newarray[$count]gt 0)) { print "$newarray[$count]\n"; } else { print "-1\n"; }
This file is to check the number of occurences of the word reject total rows rejected: 80 this file just contains the phrase reject. reject:3 reject 3 reject 4 total rejected rows: 100 total rejected rows: 90 total rejected rows: 60 total rejected rows:40 total rejected rows:40 90 rows rejected for sub 999 rows rejected for sub 100 rows rejected for sub Reject_Ao total rejected recors: 60 total rejected rows:49 reject:1 390 rows rejected for sub
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: uninitialized value error
by talexb (Chancellor) on Jan 30, 2008 at 18:19 UTC | |
by Narveson (Chaplain) on Jan 30, 2008 at 21:16 UTC | |
|
Re: uninitialized value error
by GrandFather (Saint) on Jan 31, 2008 at 00:03 UTC | |
by mercuryshipz (Acolyte) on Jan 31, 2008 at 15:40 UTC |