Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Problems with ;'s

by LostS (Friar)
on Nov 09, 2001 at 21:41 UTC ( [id://124417]=perlquestion: print w/replies, xml ) Need Help??

LostS has asked for the wisdom of the Perl Monks concerning the following question:

Hey Again,

OK Today's issue... I have a textarea field. I put alot of text in it. However the text contians characters like ;'s and #'s and @'s and $'s and stuff... So when perl see's the ; it stops... How can I tell it not to do that and make it actually print all that data into my file??

-----------------------
Billy S.
Slinar Hardtail - Guildless
Datal Ephialtes - Guildless
RallosZek.Net Admin/WebMaster
Aerynth.Net Admin/WebMaster

perl -e '$cat = "cat"; if ($cat =~ /\143\x61\x74/) { print "Its a cat! +\n"; } else { print "Thats a dog\n"; } print "\n";'

Replies are listed 'Best First'.
Re: Problems with ;'s
by dvergin (Monsignor) on Nov 09, 2001 at 22:05 UTC
    This seems unlikely. I suspect you have mis-diagnosed the problem. Can you show us some code?

    -------------------------------------------
    "Perl is a mess and that's good because the
    problem space is also a mess." - Larry Wall
    -------------------------------------------

      Ohh I just found the problem. Due to the system I am developing on I am being required to use the PHP interface/frame work system. So in the PHP I do this:
      <? $script = "/cgi-bin/hr-bin/index.cgi"; $QSTRING = $QUERY_STRING; if (isset($HTTP_POST_VARS)) { while (list ($header, $value) = each ($HTTP_POST_VARS)) { $QSTRING = $QSTRING.'&'.$header.'='.$value; } } virtual($script.'?'.$QSTRING); ?>

      Now if my input from a textarea is this (including the quotes) "I am bob; I eat babies" it passes this to the perl script:

      \"I am bob

      So that is my problem... Can anyone help me??


      -----------------------
      Billy S.
      Slinar Hardtail - Guildless
      Datal Ephialtes - Guildless
      RallosZek.Net Admin/WebMaster
      Aerynth.Net Admin/WebMaster

      perl -e '$cat = "cat"; if ($cat =~ /\143\x61\x74/) { print "Its a cat! +\n"; } else { print "Thats a dog\n"; } print "\n";'

        use CGI qw( escape ); #[...] if (isset($HTTP_POST_VARS)) { while (list ($header, $value) = each ($HTTP_POST_VARS)) { $QSTRING = $QSTRING.'&'.$header.'='.escape($value); } # I added this: ^^^^^^^ ^ }
        You might also need to escape the $header.

        Update: jryan points out that I've used a Perl module to update your PHP code. Perhaps someone can pipe up with the way to URL-encode values in PHP or you can just use the original, still-escaped query string instead of rebuilding it from the now-unescaped parameter values.

                - tye (but my friends call me "Tye")

        I think your problem lies in the fact that you're not escaping URL-special characters (ie, probably ';', though I don't remember off the top of my head). I don't really know PHP but I have to believe they have a better way of building a query string than how you're doing it. At the very least, I'm sure PHP supplies a function to URL-encode data. Use that.

        bbfu
        Seasons don't fear The Reaper.
        Nor do the wind, the sun, and the rain.
        We can be like they are.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://124417]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (6)
As of 2024-04-19 08:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found