justkar4u has asked for the wisdom of the Perl Monks concerning the following question:
Am calling this module from other .pl script and passing the file name and keyword. - Thanks Rampackage search; use strict; use warnings; sub find($$){ if ($#_ != 1) # Check the number of arguments for the command. + @ARGV is the default perl- { # Array that stores command line arguments return "Format Error:Usage- script.pl <filename> <'String'>\neg:search +.pl config_file 'X YZ'\n"; exit -1; } my $file=$_[0]; # Stores the filename my $key=$_[1]; # Stores the key my $count = 0; # To increment if keyword is found if (-e "$file") # Checks if file is present else Return Err +or { open (DATA,$file); chomp($key); # Removes the new line character from the +keyword while (defined (my $line = <DATA>)) # Search until Handle +is open { if ($line =~ /\b\Q$key\E\b/i) # Matches for the exact f +ull keyword(Does'nt show if the key is a part of another word) { return "Passed\n"; $count++; exit 0;} # Increment count if keyword found } if($count == 0) # If count is Zero, no Keyword +match was found { return "Failed\n" ; exit 1; } close (DATA); } else { return "Error: file does'nt exist\n"; exit -1; } } 1; # Must exit in true value
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Trouble using exit codes
by Eliya (Vicar) on Apr 06, 2011 at 18:16 UTC | |
by justkar4u (Novice) on Apr 06, 2011 at 20:04 UTC | |
by Eliya (Vicar) on Apr 06, 2011 at 20:19 UTC | |
by justkar4u (Novice) on Apr 06, 2011 at 21:07 UTC |