regular expressions & cgi-lib.pl

Hey.

cgi-lib.pl puts form values into a hash like so:

$input{'field'}

I need to change some of these fields. This is what I have tried:

$httpstr = "http://";

if($input{'url'} !~ m/$httpstr/i) {
   $fullUrl = $httpstr + $input{'url'};
   $input{'url'} = $fullUrl;
}

$input{'url'} unfortunately returns 0. Why is this?

TY
-D
LVL 3
SuperMarioAsked:
Who is Participating?
 
ozoConnect With a Mentor Commented:
Are you sure there are newlines in the source, not carriage-returns?
0
 
KennyIT Application ExecutiveCommented:
Instead of using a plus (+), try using a fullstop (.).

change from
  $fullUrl = $httpstr + $input{'url'};

to
  $fullUrl = $httpstr.$input{'url'};
   

Hope it helps.
0
 
ozoCommented:
$input{url}=$httpstr.$input{url};
#or
substr($input{'url'},0,0)=$httpstr;
0
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
SuperMarioAuthor Commented:
Wow man, I forgot about the concatenation operator.

Anyway, here's the other part of this problem:

$input{'comments'} =~ s/\n/<BR>\n/g;

There are still no breaks in the comments section after this - only newlines in the source.

Why?

TY
0
 
SuperMarioAuthor Commented:
I'm not sure. It looks like this:

Line one

Line two

in the source. I dunno.

-D
0
 
SuperMarioAuthor Commented:
YEAHHHHH!!
I figured it out. I changed it to a hex code (because the Comments field is transmitted through a Flash var) so instead of

s/\n/<br>\n/g;

I have

s/\x0d/<br>\n/g;

and it works perfectly!!

Thank you ozo, for that idea.

You're the man.
-D

0
All Courses

From novice to tech pro — start learning today.