Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > How to break the lines in printing to html lines?

Reply
Thread Tools

How to break the lines in printing to html lines?

 
 
Ciba LO
Guest
Posts: n/a
 
      07-06-2006
Hello,

The following script fails to break the lines in listing the directory
contents with long listing format --- see below.
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "<br>";
$out = exec("ls -l");
print "$out<br>\n";
print "<br>";

And the browser displays as:
total 24 -rwx------ 1 apache apache 132 Jul 6 11:04 test.cgi -rwx------
1 apache apache 134 Jul 6 11:02 test.cgi~ -rwxrwxrwx 1 guest guest 253
Jul 6 10:48 test_a.cgi -rwxrwxrwx 1 guest guest 257 Jul 6 10:47
test_a.cgi~ -rwxrwxrwx 1 guest guest 511 Mar 15 21:18 test_b.cgi
-rwxrwxrwx 1 guest guest 511 Mar 15 21:17 test_c.cgi

Please help me to break the lines in printing to html lines!

Thank you very much in advance!!!

Ciba

 
Reply With Quote
 
 
 
 
John W. Krahn
Guest
Posts: n/a
 
      07-06-2006
Ciba LO wrote:
>
> The following script fails to break the lines in listing the directory
> contents with long listing format --- see below.
> #!/usr/bin/perl
> print "Content-type: text/html\n\n";
> print "<br>";
> $out = exec("ls -l");


The exec() function doesn't return what you seem to think it does.

> print "$out<br>\n";


$out doesn't contain "lines" (in the HTML sense) it contains one string. Read
the documentation for the qx operator in the perlop manual:

perldoc perlop

> print "<br>";



#!/usr/bin/perl
use warnings;
use strict;

print "Content-type: text/html\n\n",
'<br>',
map( "$_<br>\n", qx[ls -l] ),
'<br>';



John
--
use Perl;
program
fulfillment
 
Reply With Quote
 
 
 
 
Sherm Pendley
Guest
Posts: n/a
 
      07-06-2006
"Ciba LO" <> writes:

> The following script fails to break the lines in listing the directory
> contents with long listing format --- see below.
> #!/usr/bin/perl
> print "Content-type: text/html\n\n";
> print "<br>";
> $out = exec("ls -l");
> print "$out<br>\n";
> print "<br>";


Exec() does not do what you think it does - the two print statements after
exec() in the above are never executed, and $out does not have the output
of the ls command.

See "perldoc -f exec" for details.

> Please help me to break the lines in printing to html lines!


First sort out the problem with the exec() above.

After that, you have two options. One, you could split $out into lines, and
print a <br> after each line like you're doing above. Or, you could replace
all the \n's in $out with <br> in one go.

The first approach would use split() - see "perldoc -f split". The second
would use regular expressions - see "perldoc perlre".

sherm--

--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      07-06-2006
Ciba LO <> wrote:

> The following script fails to break the lines in listing the directory
> contents with long listing format --- see below.



> $out = exec("ls -l");



Where does the output from ls go?

It goes to STDOUT.

In a CGI environment STDOUT ends up at the browser.

There are no <br>s in the output from ls, so there are no <br>
tags for the browser to act on.


> print "$out<br>\n";



If the ls executes, then this print statement is _never_ reached!

(Because your perl process has been replaced by the ls process.
That's what the *and never returns* means in the first line
of the description for the exec function that you are using.
)


> Please help me to break the lines in printing to html lines!



foreach my $line ( `ls -l` ) {
print "$line<br>";
}


--
Tad McClellan SGML consulting
Perl programming
Fort Worth, Texas
 
Reply With Quote
 
Ciba LO
Guest
Posts: n/a
 
      07-08-2006
Hello John, sherm, Tad and Tim!

Many thanks to you guys for replying to my post.

Your suggestions are working okayed to me. And they are exactly what I
want them to be.

Ciba

John W. Krahn wrote:
> Ciba LO wrote:
> >
> > The following script fails to break the lines in listing the directory
> > contents with long listing format --- see below.
> > #!/usr/bin/perl
> > print "Content-type: text/html\n\n";
> > print "<br>";
> > $out = exec("ls -l");

>
> The exec() function doesn't return what you seem to think it does.
>
> > print "$out<br>\n";

>
> $out doesn't contain "lines" (in the HTML sense) it contains one string. Read
> the documentation for the qx operator in the perlop manual:
>
> perldoc perlop
>
> > print "<br>";

>
>
> #!/usr/bin/perl
> use warnings;
> use strict;
>
> print "Content-type: text/html\n\n",
> '<br>',
> map( "$_<br>\n", qx[ls -l] ),
> '<br>';
>
>
>
> John
> --
> use Perl;
> program
> fulfillment


 
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
`if (!p ? i++ : 0) break;' == `if (!p){ i++; break;}' ? lovecreatesbea...@gmail.com C Programming 12 04-14-2008 07:59 AM
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
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57