Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

newbie: Printing special chars. (ie ") in perl 2

Status
Not open for further replies.

Tels

IS-IT--Management
Jul 10, 2001
290
GB
Hi, I'm in the deep end with perl at the mo, my project is to collect information from a form and print it to a file which will later be imported into a database.

So far everything has worked well (a few hiccups)and I can print web page data to a file no problem.

The problem is, that for the file to be compatible with the destination database it has to be CSV formatted (comma seperated variables)

ie:

"data","data","data"

and not

data
data
data

...which is what I get right now!!

So... whatever I print to the file has to be in that format, but if the " is so meaningful to PERL, how do we get PERL to output that character to the browser?

same goes for the comma.

I have spent ages looking at web pages trying to find some sort of howto, no such luck. If anyone can show me how I'll do a write up on it and credit you....

Cheers, I really hope that you can help me.

Tels
Win2000 Network Administrator
 
Use the escape character '\'. As in:
print "I would like \"this\" in quotes.";
 
Spot on. something so simple had me stuck for quite a while. Why isn't it made any clearer in the ActivePerl documentation?

(probably is, just wasn't looking in the right place)

Thank you.
:)
Tels Win2000 Network Administrator
 
If you don't like littering your code with escaped quotes:
Code:
my $str = "Look at these \"quotes\"";
Is the same as:
Code:
my $str = qq{Look at these "quotes"};
See the
Code:
perlfunc
manual page for more information on the following functions:
Code:
qq{abc}       - "abc". Variables are interpolated
q{abc}        - 'abc'. Variables not interpolated
qx{ls}        - Result of call to shell ls.
qw( a b c )   - [ 'a', 'b', 'c' ]
Cheers, Neil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top