On Tue, 2006-25-04 at 17:36 +0400, Monomachus wrote:
> #!/usr/bin/perl -w
> use strict;
> my $i=1;
> while (<>) {          # take one input line at time
>       chomp;  
>       if (/(\b\w*a\b)/) {

This matches only the first occurrence. You will need a loop to match
them all.

>               print "$1 found in line $i\n"; 
>               $i++;
>       } else {
>               $i++;
>       } 
> }
> ==================================
> This program does not match 'nana' line 2 (only wilma) and it DOES atch 
> 'wilma&fred' line 5 and line 8 (I think it shouldn't)...
> And is the sign '&' in \w ?? I thought that \w == [a-zA-Z0-9_] or it isn't???
> ==================================

#!/usr/bin/perl

use strict;
use warnings;

my $i=1;
while (<DATA>) {
        chomp;
        while (/(\w*a\b)/g) {
                print "$1 found in line $i\n";
        }
        $i++;
}

__END__
beforematchafter
wilma and nana
Mrs. Wilma Flinstone hommie
barney
wilma&fred
wilmafred
flinstone
mama&fred


-- 
__END__

Just my 0.00000002 million dollars worth,
   --- Shawn

"For the things we have to learn before we can do them, we learn by doing them."
  Aristotle

* Perl tutorials at http://perlmonks.org/?node=Tutorials
* A searchable perldoc is at http://perldoc.perl.org/



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to