Technology, Web & Business Forum

You are here: Technology, Web & Business Forum : Web Development : Programming : perl-reading from a file & matching?


Welcome to the Technology, Web & Business Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.


Programming Discuss programming languages such as .NET, PHP, PERL, ASP, ColdFusion, C++


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-01-2008
Junior Member
 
Join Date: Apr 2008
Posts: 2
Default perl-reading from a file & matching?

Hello all
i have this peace of code
open(RULES,'rules.txt') or die $!;
my @rules = <RULES>;
close RULES or die $!;

foreach my $rule(@rules) {
if ($request =~ m/$rule/i) {
open(ERROR,"error.html");
my @error=<ERROR>;
close(ERROR);
foreach $line(@error){
print C $line;
}

it match a text from a file or 'rules' written by regular expressions with a request
but the problem that it's matching only the first line
i mean my rules file content
\.txt
that will match any .txt extension but when i add nother line
like
\.txt
\.php
it matchs only .txt
please i really need help
__________________
Powered by Yahoo! Answers
Reply With Quote
  #2 (permalink)  
Old 05-01-2008
Junior Member
 
Join Date: May 2008
Posts: 1
Default

You need to remove the trailing newline in $rule before using it to test $request. Usually this is done with "chomp $rule;"
__________________
Powered by Yahoo! Answers
Reply With Quote
  #3 (permalink)  
Old 05-01-2008
Junior Member
 
Join Date: Apr 2008
Posts: 2
Default

Add some basic print statements so you can see EXACTLY what is in $request and EXACTLY what is in $rule, probably then you will see why it's not matching.
__________________
Powered by Yahoo! Answers
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT -5. The time now is 07:39 PM.