Home > Archive > PERL Beginners > November 2006 > Regular Expression
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Regular Expression
|
|
| Ppp Ppp 2006-11-02, 7:56 am |
| Hi All,
I want enter a regex through command line and , my program should find the regex from the file that I should suppy through comman dline
example
C:\> perl myperl.pl regex 1.txt
where regex is ths ----------> the pattern what I want to find in the 1.txt .
my program
$regexp=shift;
print "$regexp\n" if /$regexp/ ;
while (<> ) {
print " $. $regexp\n";
}
in my 1.txt file only /swa/ is present in 2 lines but this program showing that swa is present 6 times
my 1.txt file
swaghsdgg is there in psj
sjdfnsjf
swpyo 12334 is hsdfhhsf
bvfhshfjhbs
swagfhhhj fjdfkkldfkkl dfkkdkf
Thanks
Prabhat
---------------------------------
Low, Low, Low Rates! Check out Yahoo! Messenger's cheap PC-to-Phone call rates.
| |
| Dr.Ruud 2006-11-02, 7:56 am |
| ppp ppp schreef:
> I want enter a regex through command line and , my program should
> find the regex from the file that I should suppy through comman dline
>
> example
> C:\> perl myperl.pl regex 1.txt
> where regex is ths ----------> the pattern what I want to find in
> the 1.txt .
>
> my program
>
>
> $regexp=shift;
> print "$regexp\n" if /$regexp/ ;
> while (<> ) {
> print " $. $regexp\n";
> }
>
> in my 1.txt file only /swa/ is present in 2 lines but this program
> showing that swa is present 6 times
perl -wne '
BEGIN{ $r = shift; $r = qr/$r/ or die }
/$r/ and print "$.: $_"
' "swa" 1.txt
And run
perl -MO=Deparse -wne '<above code>'
to see the full source code.
--
Affijn, Ruud
"Gewoon is een tijger."
|
|
|
|
|