Simple (for some) Code change

Posted on 2003-03-29
Medium Priority
Last Modified: 2010-03-05
Help please.

The code below reads from the file badurl.txt ie: http://www.test.com and refers to sub routine &no_url

I need the code to do the same but also refer to &no_url when anything occurs after the example http://www.test.com such as http://www.test.com/ or http://www.test.com anything here

# Check for BANNED urls.

open (BANURL, "$basedir/badurl.txt");
@badurl = <BANURL>;
close (BANURL);
     foreach (@badurl) {
     chomp $_;
     $temp = $_;
     $FORM{'url'} =~ tr/A-Z/a-z/;
          if ($FORM{'url'}eq $temp) {
Question by:malkie
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 11

Accepted Solution

bcladd earned 400 total points
ID: 8230351
So, if I understand your question, you are asking to call no_url for any value in $FORM{'url'} that has a bad url as a prefix? Use regular expressions:

  if ($FORM{'url'} =~ /^$temp/) {

The ^ anchors the check at the beginning of the string so you might want to clean out leading spaces in the form before running this test.

Hope this helps, -bcl
LVL 48

Expert Comment

ID: 8231966
open BANURL, "$basedir/badurl.txt" or die "Can not open $basedir/badurl.txt $!\n";

while (<BANURL>) {
  no_url() if (/^$FORM{'url'}/i);

close BANURL;

Author Comment

ID: 8233510
Works great
God Bless

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question