On Feb 17, jimf said:
>This little script is one of my first attempts with perl, it works ok
>but I would also like to capture the output to file. Help appreciated.
>Would also appreciate constructive criticism of the script
>itself.(oh,oh!)
>
>The script basically takes a named file, and searches the file for a
>specified string.
One thing you might want to add is \Q...\E around the $string in the
regex, so that if I enter "(foo)", the regex tries to match a literal '('
instead of thinking I want to capture text.
>� � print "File to search ?\n";
>� � $logfile = <STDIN>;
>� � chomp $logfile;
>
>� � print "Search for what ?\n";
>� � $string = <STDIN>;
>� � chomp $string;
>��������
>� � open(LOG,"$logfile") or die "Unable to open $logfile:$!\n";
Open another file for output:
open RESULTS, "> $somefile" or die "Can't write to $somefile: $!\n";
>� � while(<LOG>){
>� � � � � � print if /\b$string\b/i;
print RESULTS if /\b\Q$string\E\b/i;
>� � }
>� � close(LOG);
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
[ I'm looking for programming work. If you like my work, let me know. ]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]