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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

ozoCommented:
Are you sure there are newlines in the source, not carriage-returns?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.