CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
[mad]need help.....

 



fridge
Novice

Feb 28, 2003, 7:41 PM

Post #1 of 4 (654 views)
[mad]need help..... Can't Post

Madcan anyon help? i need a perl script that tests to see if a file exists (getting the file name from the question mark after the address)and if it does, printing some html, and if it doesnt, print some different html. ive tried everything abd CANT GET IT TO WORKMad

i also need to incorporate th efollowin gbit of code in it, which only allows certain characters, and gets rid of the / on the ent of the file name (if there is one) and puts one at the start (if there isnt one):


Code
$Path = '' if ($Path !~m/^[a-zA-Z0-9 \-\_\/\.\!]*$/); 
$Path = '' if ($Path =~ m/\.\./);
chop $Path if ($Path =~ m/\/$/);
$Path = '/' . $Path if ($Path !~ m/^\//);


If anyone can help, id be realy happyWink

Mad


erichmusickwc
Novice

Feb 28, 2003, 9:43 PM

Post #2 of 4 (651 views)
Re: [fridge] [mad]need help..... [In reply to] Can't Post

Try this: (I've reformatted some of the code you gave for better readability)


Code
  

my $Path = $ENV{'QUERY_STRING'};

if ($Path !~ m/^[a-zA-Z0-9 \-\_\/\.\!]*$/ || $Path =~ m/\.\./) {
$Path = '';
}

if ($Path =~ m/\/$/) {
chop($Path);
}

if ($Path !~ m/^\//) {
$Path = '/' . $Path if ($Path !~ m/^\//);
}

if (-e($Path)) {
# Path Exists
}
else {
# Path Doesn't Exist
}



Paul
Enthusiast

Mar 1, 2003, 12:57 AM

Post #3 of 4 (646 views)
Re: [erichmusickwc] [mad]need help..... [In reply to] Can't Post

If you are going for readability then you could remove all those escapes inside the first character class and change:

m/\/$/

to

m|/$|

and

m/^\//

to

m|^/|

...and change A-Za-z0-9 to \w and then make the regex case insensitive. That means you could also remove _


(This post was edited by Paul on Mar 1, 2003, 12:59 AM)


erichmusickwc
Novice

Mar 1, 2003, 7:29 AM

Post #4 of 4 (637 views)
Re: [Paul] [mad]need help..... [In reply to] Can't Post

I'm not all that awesome with regular expressions, so I left those alone :) Thanks for pointing up ways of cleaning them up!

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives