> -----Original Message-----
> From: Jame Brooke [mailto:[EMAIL PROTECTED]
> Sent: Sunday, May 30, 2004 6:10 PM
> To: [EMAIL PROTECTED]
> Subject: Any wrong?
>
>
>
> Friend, anybody have idea regarding this problem. Assume I
> want know where the word call "fish" locate in which line
> number, and this word i save under file call nlexample.
> Assume we already know fish save under line number 2, how we
> show this?
>
> Example:nlexample
>
> I love vegetable
> I love fish
> I love perl
>
>
> my script
> -----------
>
> my $lineno;
>
>
> while (<>){
> if (/pattern/){
> print $lineno++;
> print ": $_";
> }
> }
>
> As i know we can use pattern tester to matching right? But
> why i perl no allow me compiler?
>
> [EMAIL PROTECTED] root]# ./pattern nlexample fish
> Can't open fish: No such file or directory at ./pattern line
> 7, <> line 6.
>
>
> Any comment regarding this problem, please advise.
>
>
>
>
>
>
> ---------------------------------
> Do You Yahoo!?
> Get your free @yahoo.com.hk address at Yahoo! Mail.
>
from 'perldoc perlvar'
$. Current line number for the last filehandle accessed.
So You can use this variable to know the line number.
Try something like
use strict;
my $match = shift(@ARGV);
while (defined(my $line = <>)) {
print "$.$line"
if $line =~ /$match/;
}
this shall work if you like:
perl script.pl fish fileName.txt
or
more fileName.txt | perl script.pl fish
...
Marcos
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>