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

C

cibalo

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!!!
 
B

Bart Van der Donck

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`;
 
A

anno4000

Bart Van der Donck said:
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
 
J

Jürgen Exner

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
 
S

Sherm Pendley

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--
 
C

Ciba LO

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
 
J

Joe Smith

Bart said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top