Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Handling Special Character: Best Practices?

by FitTrend (Pilgrim)
on Apr 12, 2005 at 14:53 UTC ( #447022=perlquestion: print w/replies, xml ) Need Help??
FitTrend has asked for the wisdom of the Perl Monks concerning the following question:

I've personally written several (simple and complex) web applications that utilize different programming technologies to accomplish my goals. One of the most reoccuring issues that I run into is handling special characters for different things. For example:

  • Passing Special characters to/from URLs to launch a different tool and pass parameters (some specified by a user)
  • Escaping special characters in perl code
  • formatting special characters for HTML to create pretty tables (etc) that includes user input from previous screens in the application
  • subsituting special characters for databases to avoid errors based on users who need/require %, _, ', and " in their input fields

I've realized for some time now that it is cumbersome to handle/convert between these different technologies within the main program. I even use some great perl modules from CPAN.

Generally each technology has its own methods I find.

  • URL: using URL Encoding (example)
  • Escaping with backslashes or regex
  • HTML Formatting: &gt for >, etc.
  • Subsituting special character for database storage
    $sth = $dbh->prepare("update rpttemplates set name=?, where rpttemplat +es_id ='$input{'id'}'"); $sth->execute($input{'name'});

I know there are some great modules out there to perform the formatting some of these tasks. I was curious on what my fellow monks do to handle all this data and converting it back and forth to perform the tasks typical of web based applications. What are some best practices that you follow?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://447022]
Approved by moot
help
Chatterbox?
[GotToBTru]: "I did it my $way"
[JohnCub]: I hope $way isn't a hashref. ;)
[GotToBTru]: many times i've been told I made a real hash of thiings
[GotToBTru]: so .. perhaps it should b e
[thepkd]: Just wondering why $aohoaoh[0]->{'foo '}[0]->{'bar'} would be difficult to read and understand?
[thepkd]: I am a noob and find it easier

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (14)
As of 2016-12-06 13:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (105 votes). Check out past polls.