Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: can any reply out with a better code than this??

by fenLisesi (Priest)
on Dec 06, 2007 at 07:44 UTC ( #655297=note: print w/replies, xml ) Need Help??

in reply to can any reply out with a better code than this??

can any one suggest a better code to this??
#!/usr/bin/perl -w my $string = "rid"; while (<>) { if (/($string){3}/) { print; } }
Yes, for sure:
#!/usr/bin/perl -w my $string = "rid"; while (<>) { if (/($string){3}/) { print; } }
and, arguably:
use strict; my $string = 'ri\d+'; while (my $line = <>) { if ($line =~ m{ (?: \Q$string\E ){3} }xms) { print $line; } }

Replies are listed 'Best First'.
Re^2: can any reply out with a better code than this??
by asdfghjkl (Initiate) on Dec 06, 2007 at 07:50 UTC
    the code above mentioned is not printing the matched content
      Sorry, asdfghjkl, I confused you by changing the string. Try running it with ri\d+ri\d+ri\d+ for a match. That was meant to emphasize the use of \Q...\E.
        can u suggest me a code from taking both the things from terminal itself....can i print out the matched content with my code properly.i had justed tested out for a few cases like calling some files.etc.......whether it would work for any case like that so that it need to match 3 consecutive times as per the contents of $string

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://655297]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2021-10-27 07:21 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (91 votes). Check out past polls.