Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > How to eliminate the extra 0's in printing to html lines?

Reply
Thread Tools

How to eliminate the extra 0's in printing to html lines?

 
 
cibalo@gmx.co.uk
Guest
Posts: n/a
 
      07-03-2006
Hello,

The following script produces two extra 0's at the end of the lines ---
see below.
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "# which sendmail<br>";
$out = system("which sendmail");
print "$out<br>\n";
print "<br>";
print "# which perl<br>";
$out = system("which perl");
print "$out<br>\n";
print "<br>";

And the browser displays as:
# which sendmail
/usr/sbin/sendmail 0

# which perl
/usr/bin/perl 0

Please help me to eliminate the two extra 0's at the end of the lines.
I have no idea where these 0's are coming from.

Thank you very much in advance!!!

 
Reply With Quote
 
 
 
 
Bart Van der Donck
Guest
Posts: n/a
 
      07-03-2006
(E-Mail Removed) wrote:

> The following script produces two extra 0's at the end of the lines ---
> see below.
> #!/usr/bin/perl
> print "Content-type: text/html\n\n";
> print "# which sendmail<br>";
> $out = system("which sendmail");
> print "$out<br>\n";
> print "<br>";
> print "# which perl<br>";
> $out = system("which perl");
> print "$out<br>\n";
> print "<br>";
>
> And the browser displays as:
> # which sendmail
> /usr/sbin/sendmail 0
>
> # which perl
> /usr/bin/perl 0
>
> Please help me to eliminate the two extra 0's at the end of the lines.
> I have no idea where these 0's are coming from.


I see the same results here. The problem is that you can't trust the
return value of the 'system'-command. The following should work:

$out = `which perl`;

--
Bart

 
Reply With Quote
 
 
 
 
anno4000@zrz.tu-berlin.de
Guest
Posts: n/a
 
      07-03-2006
Bart Van der Donck <(E-Mail Removed)> wrote in comp.lang.perl.misc:
> (E-Mail Removed) wrote:
>
> > The following script produces two extra 0's at the end of the lines ---
> > see below.
> > #!/usr/bin/perl
> > print "Content-type: text/html\n\n";
> > print "# which sendmail<br>";
> > $out = system("which sendmail");
> > print "$out<br>\n";
> > print "<br>";
> > print "# which perl<br>";
> > $out = system("which perl");
> > print "$out<br>\n";
> > print "<br>";
> >
> > And the browser displays as:
> > # which sendmail
> > /usr/sbin/sendmail 0
> >
> > # which perl
> > /usr/bin/perl 0
> >
> > Please help me to eliminate the two extra 0's at the end of the lines.
> > I have no idea where these 0's are coming from.

>
> I see the same results here. The problem is that you can't trust the
> return value of the 'system'-command.


You can trust it to be what it it supposed to be, but that is not the
output of the invoked command.

> The following should work:
>
> $out = `which perl`;


Read "perldoc -f system" with attention to the third paragraph to see
*why* this works.

Anno
 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      07-03-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> The following script produces two extra 0's at the end of the lines
> --- see below.
> #!/usr/bin/perl
> print "Content-type: text/html\n\n";
> print "# which sendmail<br>";
> $out = system("which sendmail");
> print "$out<br>\n";
> print "<br>";
> print "# which perl<br>";
> $out = system("which perl");
> print "$out<br>\n";
> print "<br>";
>
> And the browser displays as:
> # which sendmail
> /usr/sbin/sendmail 0
>
> # which perl
> /usr/bin/perl 0


That's exactly what should happen in this script.

> Please help me to eliminate the two extra 0's at the end of the lines.
> I have no idea where these 0's are coming from.


You are printing them
If you don't want to see the return value of your system() calls, then don't
print it, i.e. change
print "$out<br>\n";
to
print "<br>\n";

jue


 
Reply With Quote
 
Sherm Pendley
Guest
Posts: n/a
 
      07-03-2006
(E-Mail Removed) writes:

> The following script produces two extra 0's at the end of the lines ---
> see below.
> #!/usr/bin/perl
> print "Content-type: text/html\n\n";
> print "# which sendmail<br>";
> $out = system("which sendmail");
> print "$out<br>\n";
> print "<br>";
> print "# which perl<br>";
> $out = system("which perl");
> print "$out<br>\n";
> print "<br>";
>
> And the browser displays as:
> # which sendmail
> /usr/sbin/sendmail 0
>
> # which perl
> /usr/bin/perl 0
>
> Please help me to eliminate the two extra 0's at the end of the lines.
> I have no idea where these 0's are coming from.


They're the value of $out when it's printed. System() does not do what you
think it does. For details have a look at the docs for the system() function:

perldoc -f system

sherm--

--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      07-03-2006
"Bart Van der Donck" <(E-Mail Removed)> wrote in
news:(E-Mail Removed) ups.com:

> The problem is that you can't trust the
> return value of the 'system'-command.


In what way does the return value of the system function match its
documentation?

perldoc -f system

Sinan

--
A. Sinan Unur <(E-Mail Removed)>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc...uidelines.html

 
Reply With Quote
 
Ciba LO
Guest
Posts: n/a
 
      07-04-2006
Hello Bart, Steffen, Anno, jue, sherm and Sinan!

Many thanks to you guys for replying to my post. Both the backquote
substitution and the omission of $out in the print statements are
working okayed to me.

Ciba

Bart Van der Donck wrote:
>
> I see the same results here. The problem is that you can't trust the
> return value of the 'system'-command. The following should work:
>
> $out = `which perl`;
>
> --
> Bart


 
Reply With Quote
 
Joe Smith
Guest
Posts: n/a
 
      07-05-2006
Bart Van der Donck wrote:

> I see the same results here. The problem is that you can't trust the
> return value of the 'system'-command.


You most certainly _CAN_ trust the return value of the system() function.

The return value is documented, it's just not what you think it is.

if (system($command) == 0) {
print "The command '$command' executed with no errors\n";
} else {
warn "The command '$command' returned a non-zero error code: $?\n";
}

-Joe
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Does return-by-value mean extra copies and extra overhead? mathieu C++ 3 09-04-2009 04:25 PM
brochure printing,online yearbook,printing,books printing,publishing elie Computer Support 0 08-21-2007 05:50 AM
brochure printing,online yearbook,printing,books printing,publishing elie Computer Support 0 08-21-2007 05:28 AM
brochure printing,online yearbook,printing,books printing,publishing elie Computer Support 0 08-18-2007 10:11 AM



Advertisments