By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,904 Members | 1,089 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,904 IT Pros & Developers. It's quick & easy.

How to search a regex without replacing it in perl

P: 2
I want to search a regex in perl without replacing it and without going line by line to search it

Any help will be apriciable

Thanks in advance
Feb 3 '09 #1
Share this Question
Share on Google+
7 Replies


Icecrack
Expert 100+
P: 174
Question:
What have your tried so far?

How can we work with what you want, if we do not know the information we are looking for?

Thanks

Charlie
Feb 3 '09 #2

KevinADC
Expert 2.5K+
P: 4,059
You can't search a regexp, the question makes no sense. You can search a file or a database, but you can't search a regexp.
Feb 3 '09 #3

P: 2
I have tried to serch each and every line in the file using

Expand|Select|Wrap|Line Numbers
  1. open FH,"log";
  2. for $line(<FH>){
  3. if( $line =~ m/regexp/ )
  4. {
  5. }
  6. }
but i dont want to look each and every line in the file

Thanks
Feb 3 '09 #4

numberwhun
Expert Mod 2.5K+
P: 3,503
@Vipul03
If you don't try and match against every line, how are you going to have a proper search? Inside of the if statement, if you don't do anything, like print the line or the line number, then you will never know that there was a match.

Regards,

Jeff
Feb 3 '09 #5

KevinADC
Expert 2.5K+
P: 4,059
maybe this is what you want, hard to say because I guess you think we can read your mind and understand your vague question:

Expand|Select|Wrap|Line Numbers
  1. open FH,"log";
  2. while (my $line = <FH>){
  3.    if( $line =~ m/regexp/ ) {
  4.       "Found regexp in $line\n";
  5.       last; $stops searching after first match
  6.    }  
  7. }
  8. close FH;
  9.  
If thats not what you are trying to do then please explain yourself properly so other people can understand what your requirements are.
Feb 3 '09 #6

Icecrack
Expert 100+
P: 174
@KevinADC
I know in the quick making of that script you may of made a mistake or typo at
Expand|Select|Wrap|Line Numbers
  1. $stops Searching
Feb 3 '09 #7

KevinADC
Expert 2.5K+
P: 4,059
@Icecrack
Yes thanks, should have been "#stops searching" instead of "$stops Searching".
Feb 3 '09 #8

Post your reply

Sign in to post your reply or Sign up for a free account.