print string in file

--0-319478403-1282046382=:54054
Content-Type: text/plain; charset=us-ascii

Hi All,

I need to print some string into the file.
the string is like this : "<?xml version="1.0" encoding="UTF-8"?>"

i have written code like this :
print MYFILE "<?xml version="1.0" encoding="UTF-8"?>\n" where MYFILE is a file
handler.

if i run this code , it is giving so many syntax errors.
any advice please

Regards
Irfan



--0-319478403-1282046382=:54054--
Irfan Sayed [ Di, 17 August 2010 13:59 ] [ ID #2046195 ]

RE: print string in file

From: Irfan Sayed

> I need to print some string into the file.
> the string is like this : "<?xml version=3D"1.0" encoding=3D"UTF-8"?>"
>
> i have written code like this :
> print MYFILE "<?xml version=3D"1.0" encoding=3D"UTF-8"?>\n" where =
MYFILE
is a file
> handler.
>
> if i run this code , it is giving so many syntax errors.
> any advice please

You can't have unescaped quotes in a quoted string. Try this:

print MYFILE "<?xml version=3D\"1.0\" encoding=3D\"UTF-8\"?>\n";

or this:

print MYFILE '<?xml version=3D"1.0" encoding=3D"UTF-8"?>' . "\n";

Bob McConnell

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Bob McConnell [ Di, 17 August 2010 14:11 ] [ ID #2046196 ]

Re: print string in file

On 10-08-17 07:59 AM, Irfan Sayed wrote:
> Hi All,
>
> I need to print some string into the file.
> the string is like this : "<?xml version="1.0" encoding="UTF-8"?>"
>
> i have written code like this :
> print MYFILE "<?xml version="1.0" encoding="UTF-8"?>\n" where MYFILE is a file
> handler.
>
> if i run this code , it is giving so many syntax errors.
> any advice please
>
> Regards
> Irfan
>
>
>

Use a backslash to escape the internal double quotes:

print MYFILE "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";


--
Just my 0.00000002 million dollars worth,
Shawn

Programming is as much about organization and communication
as it is about coding.

The secret to great software: Fail early & often.

Eliminate software piracy: use only FLOSS.

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Shawn H Corey [ Di, 17 August 2010 14:14 ] [ ID #2046197 ]

Re: print string in file

Irfan Sayed wrote:

> print MYFILE "<?xml version="1.0" encoding="UTF-8"?>\n"
> where MYFILE is a file handler.

s/handler/handle/

print $MYFILE qq{<?xml version="1.0" encoding="UTF-8"?>\n};

--
Ruud

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
rvtol+usenet [ Di, 17 August 2010 21:05 ] [ ID #2046200 ]

Re: print string in file

--0-2084779122-1282199432=:78646
Content-Type: text/plain; charset=us-ascii

Thanks all
it worked.

--Irfan




________________________________
From: Dr.Ruud <rvtol+usenet [at] isolution.nl>
To: beginners [at] perl.org
Sent: Wed, August 18, 2010 12:35:57 AM
Subject: Re: print string in file

Irfan Sayed wrote:

> print MYFILE "<?xml version="1.0" encoding="UTF-8"?>\n" where MYFILE is a file
>handler.

s/handler/handle/

print $MYFILE qq{<?xml version="1.0" encoding="UTF-8"?>\n};

-- Ruud

-- To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/



--0-2084779122-1282199432=:78646--
Irfan Sayed [ Do, 19 August 2010 08:30 ] [ ID #2046340 ]
Perl » gmane.comp.lang.perl.beginners » print string in file

Vorheriges Thema: Perl modules
Nächstes Thema: Newbie: Perl how evaluate files newer than an hour within ftp