RE: Replacing printf by print

That's the whole problem.=0D
I am replacing it since there are some % sign in the strings being
passed making the program crash. Replacement solves the problem as such,
but wanted to countercheck, If these replacements could create any
problem anywhere else! , or lator in the program?
(Although I don't think it should).

Thanks and regards,
Pradeep
-----Original Message-----
From: Jeff 'japhy' Pinyan [mailto:japhy [at] perlmonk.org]=0D
Sent: Friday, July 22, 2005 5:31 PM
To: Pradeep Goel (WT01 - TELECOM SOLUTIONS)
Cc: beginners [at] perl.org
Subject: Re: Replcaing printf by print

On Jul 22, pradeep.goel [at] wipro.com said:

> Does replacing printf by print make any difference in the program?
> Especially at places where there is no format string passed or just $_
> is passed?

It probably doesn't have a noticeable difference unless you compare the=0D
running of it many, MANY times. But using printf() needlessly is silly,

and in some cases, dangerous. If you have a % sign in your string,
printf=0D
will expect an argument to go with it.

--=0D
Jeff "japhy" Pinyan % How can we ever be the sold short or
RPI Acacia Brother #734 % the cheated, we who for every service
http://japhy.perlmonk.org/ % have long ago been overpaid?
http://www.perlmonks.org/ % -- Meister Eckhart



Confidentiality Notice=0D

The information contained in this electronic message and any attachments to=
this message are intended
for the exclusive use of the addressee(s) and may contain confidential or=
privileged information. If
you are not the intended recipient, please notify the sender at Wipro or=
Mailadmin [at] wipro.com immediately
and destroy all copies of this message and any attachments.

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>
pradeep.goel [ Fr, 22 Juli 2005 14:14 ] [ ID #891121 ]

RE: Replacing printf by print

On Jul 22, pradeep.goel [at] wipro.com said:

> I am replacing it since there are some % sign in the strings being
> passed making the program crash. Replacement solves the problem as such,
> but wanted to countercheck, If these replacements could create any
> problem anywhere else! , or lator in the program?

The only problem there might be is that print() is susceptible to to the
$, and $\ variables. The $, variable defines what gets printed in between
the list of strings you pass to print(), and $\ defines what gets printed
after the strings you pass to print(). Both default to the empty string,
but if you were to change them, for some reason, print()s output would be
affected (but printf()s would not).

print "a", "b", "c"; # abc

$, = "!";
print "a", "b", "c"; # a!b!c

$\ = "?";
print "a", "b", "c"; # a!b!c?

But this is not likely to happen, methinks.

--
Jeff "japhy" Pinyan % How can we ever be the sold short or
RPI Acacia Brother #734 % the cheated, we who for every service
http://japhy.perlmonk.org/ % have long ago been overpaid?
http://www.perlmonks.org/ % -- Meister Eckhart

--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>
japhy [ Fr, 22 Juli 2005 14:29 ] [ ID #891122 ]
Perl » gmane.comp.lang.perl.beginners » RE: Replacing printf by print

Vorheriges Thema: Replcaing printf by print
Nächstes Thema: pointer