On Sun, 17 Feb 2002 19:02:36 -0800, [EMAIL PROTECTED] (Tetsuo) wrote:
>one big string variable). It works but can anyone tell me what the best way
>to report where in the file the match occurs? Also, is there a quicker way
>of getting the contents of a file in a string rather than my loop?
The variable $. gives you the line number. So
print 'match at ',$.,"\n";
You are using nested while loops to iterate
thru a file, this isn't necessary. Also you don't need to
open a file just to loop thru it.
Try something like:
my $file = 'c:/davidcode/perlbeast/*.secret';
while (<$file>){
print "$file: $. :$_\n" if /$regexp/;
}
>
>Here is the code:
>
>#finding regular expressions in perl>>
>
>print "Enter a regular expression to use \n";
>my $regexp = <STDIN>;
>chomp $regexp;
>print "Your regular expression is $regexp \n";
>my $s="";
>while(defined($foo = <c:/davidcode/perlbeast/*.secret>)){ #or whatever file
>path you want...
> $foo =~ s#.*/##;
> open(TEST,$foo) || die "cannot open file";
> while(defined($line = <TEST>)){
> $s = $s . $line;
> }
> if($s =~ /$regexp/){
> print "match \n";
> }
>
> close(TEST) || die "cannot close file";
>}
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]