ChrisCK has asked for the wisdom of the Perl Monks concerning the following question:
I want to pass in an argument so that the script only looks for a certain pattern. This is not working for me. Something about my 'If' statements is erroring.
If I remove all the options and 'IF' statement, the actual printing of the error message works but I want to choose what it will be searching for.
use strict; use warnings; my $file = $ARGV[0]; my $purpose = $ARGV[1]; open( FILE, "$file" ) or die "Can't open $file: $!"; while ( <FILE> ) { If ($purpose = "sqlerrors") { print if ( /SQL Error:/i .. m{^\s*$}); } If ($purpose = "othererrors") { print if ( /OTHER Error:/i .. m{^\s*$}); } If ($purpose = "missingfile") { print if ( /Missing File:/i .. m{^\s*$}); } } close FILE;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Process File Different Way Based on Passed in Argument
by davido (Cardinal) on Jan 22, 2016 at 00:17 UTC | |
by Athanasius (Archbishop) on Jan 22, 2016 at 02:40 UTC | |
by davido (Cardinal) on Jan 22, 2016 at 05:27 UTC | |
|
Re: Process File Different Way Based on Passed in Argument
by vinoth.ree (Monsignor) on Jan 22, 2016 at 04:00 UTC | |
by afoken (Chancellor) on Jan 22, 2016 at 05:00 UTC | |
|
Re: Process File Different Way Based on Passed in Argument
by Anonymous Monk on Jan 22, 2016 at 15:36 UTC |