You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Ryszard Lach <si...@id.pl> on 2000/06/14 18:33:59 UTC

Beginner's question

Hi!

I've read docs about using embperl and HTML escaping, I tried to display e.g.
forms data (it works fine),  but I still don't know, how to embedd such a simple
code in html page:

open(FILE,"</path/to/file");
while(<FILE>) {
	print;
}

Could anybody help me?

T.I.A.

-- 
Ryszard Łach
Internet Designers s.c. 
http://www.id.pl

Re: Beginner's question

Posted by Ryszard Lach <si...@id.pl>.
On Fri, Jun 16, 2000 at 02:12:48PM +0200, Gerald Richter wrote:
> >
> > Does the same concern opening pipes (i.e. commands, not named
> > pipes)  as files?
> >
> > open(FILE,"cat \</etc/passwd |")
> > while (\<FILE>) {
> > 	print OUT $_;
> > }
> >
> > doesn't produce any output....
> >
> 
> Embperl makes no difference here, but you may check the return value from
> open and $! . Maybe you don't have permission to execute cat as www server
> user, or cat is not in your path.

No, that is not the proble, because:

1. This was a simpler example, in fact I tried to use


open (FILE, "/usr/local/qmailanalog/bin/zsenders \</var/log/qmail/qmail.log |") or die;

(Sorry for this change, the version with cat was written quickly just to be
sure, that qmailanalog is not the problem)

2. "/usr/local/qmailanalog/bin/zsenders \</var/log/qmail/qmail.log |" 

was executed without problems from within php3 script....

Once more, wat is happening with following example:



open(FILE,"/bin/cat \</etc/passwd |") or die;
 while (\<FILE>) {
     print OUT $_;
 }

causes browser to wait indefinitly long for reply.

Any more ideas?

-- 
Ryszard Łach
Internet Designers s.c. 
http://www.id.pl

RE: Beginner's question

Posted by Gerald Richter <ri...@ecos.de>.
>
> Does the same concern opening pipes (i.e. commands, not named
> pipes)  as files?
>
> open(FILE,"cat \</etc/passwd |")
> while (\<FILE>) {
> 	print OUT $_;
> }
>
> doesn't produce any output....
>

Embperl makes no difference here, but you may check the return value from
open and $! . Maybe you don't have permission to execute cat as www server
user, or cat is not in your path.

Gerald


Re: Beginner's question

Posted by Ryszard Lach <si...@id.pl>.
On Fri, Jun 16, 2000 at 09:54:53AM +0200, Gerald Richter wrote:
> >             print "\<table>\n";
> 
>              print OUT "\<table>\n";
> ...
> 
> > 
> >         print "\</table>";
> 
>          print OUT "\</table>";
> 
> or set optRedirectStdout in your EMBPERL_OPTIONS

OK, now it works, thanks.

Does the same concern opening pipes (i.e. commands, not named pipes)  as files? 

open(FILE,"cat \</etc/passwd |")
while (\<FILE>) {
	print OUT $_;
}

doesn't produce any output....

-- 
Ryszard Łach
Internet Designers s.c. 
http://www.id.pl

Re: Beginner's question

Posted by Ryszard Lach <si...@id.pl>.
On Fri, Jun 16, 2000 at 08:35:03AM -0400, Erich L. Markert wrote:
> Some things to notice...
> 
> In your code you have: "qmail.log|" in your open() statement - I don't
> think you want that if you are simply reading the file.

No, I'm not reading the file, I'm reading output form 


/path/command </path/stdin_to_this_command |

pipe.

> Also, ALWAYS, ALWAY, ALWAYS close file handles via close() if you are
> using open().

OK, OK, I always do close files (this time was a bad exception), and adding
close(FILE) didn't help....

> 
> Ryszard Lach wrote:
> > 
> > On Fri, Jun 16, 2000 at 08:41:18AM +0200, Gerald Richter wrote:
> > > >
> > > > open (FILE, "/path/command \</path/file |") or die;
> > > >
> > > > while (\<FILE>) {
> > > >     print OUT $_;
> > > > }
> > > >
> > > > did not. I received Internal Server Error and the following in
> > > > apache's error
> > > > log:
> > > >
> > > > [Thu Jun 15 17:42:39 2000] [error] [client 192.168.1.66]
> > > > malformed header from
> > > > script. Bad header=<table>: /usr/lib/cgi-bin/embpcgi.pl
> > > >
> > > > what means, embperl skipped all html stuff inserted before script
> > > > part. Do you
> > > > have any ideas?
> > > >
> > >
> > > I would guess it's the other way round. Your command has, for whatever
> > > reasons, printed directly to stdout (and that will come out before the
> > > output from Embperl), instead of the redirection to <FILE>.
> > 
> > Well, I wouldn't say so. In this case the output would be seeable before static
> > html tags, but it isn't.
> > 
> > Look at this complete page code:
> > 
> > ########################
> > <html>
> > <head>
> > <title>Statystyki poczty - summary of senders</title>
> > </head>
> > 
> > <body>
> > [-
> >     $escmode = 0;
> >     open(FILE, "/usr/local/qmailanalog/bin/zsenders
> > \</var/log/qmail/qmail.log|") or  die "Cant open file";
> >     while(\<FILE>) {
> >         if ( m/^mess\s+/ ){
> >             print OUT $_,"<br>";
> >             next;
> >         }
> >         else {
> >             print "\<table>\n";
> >             $_ =~ s/\s+/\<td>/g;
> >             print OUT "\<tr>\<td>$_\<br>\n";
> >             last;
> >         }
> >     }
> > 
> >         while ( \<FILE> ) {
> >             $_ =~ s/\</&lt;/g;
> >             $_ =~ s/>/&gt;/;
> >             $_ =~ s/^\s*/\<td>/;
> >             $_ = s/\s+/\<td>/;
> >             PRINT OUT "\<tr>",$_,"\n";
> >         }
> > 
> >         print "\</table>";
> >     $escmode = 1;
> > -]
> > </body>
> > </html>
> > ########################
> > 
> > This page produces (by embpexec.pl):
> > 
> > <table>
> > </table><html>
> > <head>
> > <title>Statystyki poczty - summary of senders</title>
> > </head>
> > 
> > <body>
> > <tr><td><br>
> > </body>
> > </html>
> > ############################
> > 
> > What is wrong with it? How can I debug this?
> > 
> > Siaco.
> > 
> > --
> > Ryszard ?ach
> > Internet Designers s.c.
> > http://www.id.pl
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
> > For additional commands, e-mail: embperl-help@perl.apache.org
> 
> --
> __________________________________________________________
> Mr. Erich L. Markert                     emarkert@pace.edu
> Computer Learning Center		 TEL (914)422-4328
> Pace University
> 1 Martine Ave
> White Plains, New York 10606-1932
> 
> Those who do not understand Unix are condemned to reinvent it, poorly.
>                 -- Henry Spencer
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
> For additional commands, e-mail: embperl-help@perl.apache.org
> 

-- 
Ryszard Łach
Internet Designers s.c. 
http://www.id.pl

Re: Beginner's question

Posted by "Erich L. Markert" <em...@pace.edu>.
Some things to notice...

In your code you have: "qmail.log|" in your open() statement - I don't
think you want that if you are simply reading the file.

Also, ALWAYS, ALWAY, ALWAYS close file handles via close() if you are
using open().

Ryszard Lach wrote:
> 
> On Fri, Jun 16, 2000 at 08:41:18AM +0200, Gerald Richter wrote:
> > >
> > > open (FILE, "/path/command \</path/file |") or die;
> > >
> > > while (\<FILE>) {
> > >     print OUT $_;
> > > }
> > >
> > > did not. I received Internal Server Error and the following in
> > > apache's error
> > > log:
> > >
> > > [Thu Jun 15 17:42:39 2000] [error] [client 192.168.1.66]
> > > malformed header from
> > > script. Bad header=<table>: /usr/lib/cgi-bin/embpcgi.pl
> > >
> > > what means, embperl skipped all html stuff inserted before script
> > > part. Do you
> > > have any ideas?
> > >
> >
> > I would guess it's the other way round. Your command has, for whatever
> > reasons, printed directly to stdout (and that will come out before the
> > output from Embperl), instead of the redirection to <FILE>.
> 
> Well, I wouldn't say so. In this case the output would be seeable before static
> html tags, but it isn't.
> 
> Look at this complete page code:
> 
> ########################
> <html>
> <head>
> <title>Statystyki poczty - summary of senders</title>
> </head>
> 
> <body>
> [-
>     $escmode = 0;
>     open(FILE, "/usr/local/qmailanalog/bin/zsenders
> \</var/log/qmail/qmail.log|") or  die "Cant open file";
>     while(\<FILE>) {
>         if ( m/^mess\s+/ ){
>             print OUT $_,"<br>";
>             next;
>         }
>         else {
>             print "\<table>\n";
>             $_ =~ s/\s+/\<td>/g;
>             print OUT "\<tr>\<td>$_\<br>\n";
>             last;
>         }
>     }
> 
>         while ( \<FILE> ) {
>             $_ =~ s/\</&lt;/g;
>             $_ =~ s/>/&gt;/;
>             $_ =~ s/^\s*/\<td>/;
>             $_ = s/\s+/\<td>/;
>             PRINT OUT "\<tr>",$_,"\n";
>         }
> 
>         print "\</table>";
>     $escmode = 1;
> -]
> </body>
> </html>
> ########################
> 
> This page produces (by embpexec.pl):
> 
> <table>
> </table><html>
> <head>
> <title>Statystyki poczty - summary of senders</title>
> </head>
> 
> <body>
> <tr><td><br>
> </body>
> </html>
> ############################
> 
> What is wrong with it? How can I debug this?
> 
> Siaco.
> 
> --
> Ryszard £ach
> Internet Designers s.c.
> http://www.id.pl
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
> For additional commands, e-mail: embperl-help@perl.apache.org

--
__________________________________________________________
Mr. Erich L. Markert                     emarkert@pace.edu
Computer Learning Center		 TEL (914)422-4328
Pace University
1 Martine Ave
White Plains, New York 10606-1932

Those who do not understand Unix are condemned to reinvent it, poorly.
                -- Henry Spencer

RE: Where should I put common Perl functions and Embperl [$subs$]?

Posted by Gerald Richter <ri...@ecos.de>.
Hi,
>
> trying to fine-tune my Embperl performance, I wonder where I should
> place site-wide Perl functions and Embperl subs [$ ... $] to get
> best performance.
>
> >From the docs, I learned that *Embperl subs* are best placed in
> their own file and included via the Embperl Execute command,
> using import => 1.
>
> For "ordinary" Perl subs, I tried the same thing, putting them
> into an own file, surrounding them with [! !] to execute just once.
> However, Embperl does not seem to import the sub definitions at all.
>
> Should I put the subs into an ordinary .pm and use Exporter and
> use '...' instead?
>

Yes.

If you like, you could also put your [$ sub $] in a pm file, so it's side
wide available. It's not very well documented. See test/html/subimp.pm for
an example. If you like to have them exported, you need to add the code for
this to subimp.pm.

Gerald





-------------------------------------------------------------
Gerald Richter    ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting

Post:       Tulpenstrasse 5         D-55276 Dienheim b. Mainz
E-Mail:     richter@ecos.de         Voice:    +49 6133 925151
WWW:        http://www.ecos.de      Fax:      +49 6133 925152
-------------------------------------------------------------


Where should I put common Perl functions and Embperl [$subs$]?

Posted by Thomas Corte <th...@hp9000.do.knipp.de>.
Hi everybody,

trying to fine-tune my Embperl performance, I wonder where I should
place site-wide Perl functions and Embperl subs [$ ... $] to get
best performance.

RE: Beginner's question

Posted by Gerald Richter <ri...@ecos.de>.
>             print "\<table>\n";

             print OUT "\<table>\n";
...

> 
>         print "\</table>";

         print OUT "\</table>";

or set optRedirectStdout in your EMBPERL_OPTIONS

Gerald




Re: Beginner's question

Posted by Ryszard Lach <si...@id.pl>.
On Fri, Jun 16, 2000 at 08:41:18AM +0200, Gerald Richter wrote:
> >
> > open (FILE, "/path/command \</path/file |") or die;
> >
> > while (\<FILE>) {
> >     print OUT $_;
> > }
> >
> > did not. I received Internal Server Error and the following in
> > apache's error
> > log:
> >
> > [Thu Jun 15 17:42:39 2000] [error] [client 192.168.1.66]
> > malformed header from
> > script. Bad header=<table>: /usr/lib/cgi-bin/embpcgi.pl
> >
> > what means, embperl skipped all html stuff inserted before script
> > part. Do you
> > have any ideas?
> >
> 
> I would guess it's the other way round. Your command has, for whatever
> reasons, printed directly to stdout (and that will come out before the
> output from Embperl), instead of the redirection to <FILE>.

Well, I wouldn't say so. In this case the output would be seeable before static
html tags, but it isn't. 

Look at this complete page code:

########################
<html>
<head>
<title>Statystyki poczty - summary of senders</title>
</head>

<body>
[-
    $escmode = 0;
    open(FILE, "/usr/local/qmailanalog/bin/zsenders
\</var/log/qmail/qmail.log|") or  die "Cant open file";
    while(\<FILE>) {
        if ( m/^mess\s+/ ){
            print OUT $_,"<br>";
            next;
        }
        else {
            print "\<table>\n";
            $_ =~ s/\s+/\<td>/g;
            print OUT "\<tr>\<td>$_\<br>\n";
            last;
        }
    }

        while ( \<FILE> ) {
            $_ =~ s/\</&lt;/g;
            $_ =~ s/>/&gt;/;
            $_ =~ s/^\s*/\<td>/;
            $_ = s/\s+/\<td>/;
            PRINT OUT "\<tr>",$_,"\n";
        }

        print "\</table>";
    $escmode = 1;
-]
</body>
</html>
########################

This page produces (by embpexec.pl):

<table>   
</table><html>
<head>
<title>Statystyki poczty - summary of senders</title>
</head>

<body>
<tr><td><br>
</body>
</html>
############################

What is wrong with it? How can I debug this?

Siaco.


-- 
Ryszard Łach
Internet Designers s.c. 
http://www.id.pl

RE: Beginner's question

Posted by Gerald Richter <ri...@ecos.de>.
>
> open (FILE, "/path/command \</path/file |") or die;
>
> while (\<FILE>) {
>     print OUT $_;
> }
>
> did not. I received Internal Server Error and the following in
> apache's error
> log:
>
> [Thu Jun 15 17:42:39 2000] [error] [client 192.168.1.66]
> malformed header from
> script. Bad header=<table>: /usr/lib/cgi-bin/embpcgi.pl
>
> what means, embperl skipped all html stuff inserted before script
> part. Do you
> have any ideas?
>

I would guess it's the other way round. Your command has, for whatever
reasons, printed directly to stdout (and that will come out before the
output from Embperl), instead of the redirection to <FILE>.

Gerald



-------------------------------------------------------------
Gerald Richter    ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting

Post:       Tulpenstrasse 5         D-55276 Dienheim b. Mainz
E-Mail:     richter@ecos.de         Voice:    +49 6133 925151
WWW:        http://www.ecos.de      Fax:      +49 6133 925152
-------------------------------------------------------------


Re: Beginner's question

Posted by Ryszard Lach <si...@id.pl>.
On Wed, Jun 14, 2000 at 12:45:06PM -0400, Erich L. Markert wrote:
> Try:
> 
> [-
> open(FILE,"</path/file") || die "Can't open file";
> $escmode = 0; # needed for the subsequent print in "while" 
> 	      # otherwise Embperl will complain
> while(<FILE>){
> 	print;
> }
> $escmode = 1;
> close(FILE);
> -]

Well the following did work:

open (FILE, "\</path/file") or die;

while (\<FILE>) {
	print OUT $_;
}

But a little bit different:

open (FILE, "/path/command \</path/file |") or die;

while (\<FILE>) {
    print OUT $_;
}

did not. I received Internal Server Error and the following in apache's error
log:

[Thu Jun 15 17:42:39 2000] [error] [client 192.168.1.66] malformed header from
script. Bad header=<table>: /usr/lib/cgi-bin/embpcgi.pl

what means, embperl skipped all html stuff inserted before script part. Do you
have any ideas?


Siaco.

-- 
Ryszard Łach
Internet Designers s.c. 
http://www.id.pl

Re: Beginner's question

Posted by "Erich L. Markert" <em...@pace.edu>.
Yep, my mistake.

jbodnar@team-linux.com wrote:
> 
> $escmode has nothing to do with being able to use print() inside [- -]. In
> order to do that you have to turn on optRedirectStdout as part of your
> EMBPERL_OPTIONS in your conf file.
> 
> On 14-Jun-2000 Erich L. Markert wrote:
> > Try:
> >
> > [-
> > open(FILE,"</path/file") || die "Can't open file";
> > $escmode = 0; # needed for the subsequent print in "while"
> >             # otherwise Embperl will complain
> > while(<FILE>){
> >       print;
> > }
> > $escmode = 1;
> > close(FILE);
> > -]
> >
> > Ryszard Lach wrote:
> >>
> >> Hi!
> >>
> >> I've read docs about using embperl and HTML escaping, I tried to display
> >> e.g.
> >> forms data (it works fine),  but I still don't know, how to embedd such a
> >> simple
> >> code in html page:
> >>
> >> open(FILE,"</path/to/file");
> >> while(<FILE>) {
> >>         print;
> >> }
> >>
> >> Could anybody help me?
> >>
> >> T.I.A.
> >>
> >> --
> >> Ryszard £ach
> >> Internet Designers s.c.
> >> http://www.id.pl
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
> >> For additional commands, e-mail: embperl-help@perl.apache.org
> >
> > --
> > __________________________________________________________
> > Mr. Erich L. Markert                     emarkert@pace.edu
> > Computer Learning Center               TEL (914)422-4328
> > Pace University
> > 1 Martine Ave
> > White Plains, New York 10606-1932
> >
> > Those who do not understand Unix are condemned to reinvent it, poorly.
> >                 -- Henry Spencer
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
> > For additional commands, e-mail: embperl-help@perl.apache.org
> 
> --
> Jason Bodnar + jbodnar@team-linux.com + Team Linux
> 
> Homer:  I keep hearing this horrible irregular thumping noise.
> 
> Pump Jockey:
>         It's your heart.  And I think it's on its last thump.
> 
> Homer:  Whew, I was afraid it was my transmission.
> 
>                    Homer's Triple Bypass

--
__________________________________________________________
Mr. Erich L. Markert                     emarkert@pace.edu
Computer Learning Center		 TEL (914)422-4328
Pace University
1 Martine Ave
White Plains, New York 10606-1932

Those who do not understand Unix are condemned to reinvent it, poorly.
                -- Henry Spencer

Re: Beginner's question

Posted by jb...@team-linux.com.
$escmode has nothing to do with being able to use print() inside [- -]. In
order to do that you have to turn on optRedirectStdout as part of your
EMBPERL_OPTIONS in your conf file.

On 14-Jun-2000 Erich L. Markert wrote:
> Try:
> 
> [-
> open(FILE,"</path/file") || die "Can't open file";
> $escmode = 0; # needed for the subsequent print in "while" 
>             # otherwise Embperl will complain
> while(<FILE>){
>       print;
> }
> $escmode = 1;
> close(FILE);
> -]
> 
> Ryszard Lach wrote:
>> 
>> Hi!
>> 
>> I've read docs about using embperl and HTML escaping, I tried to display
>> e.g.
>> forms data (it works fine),  but I still don't know, how to embedd such a
>> simple
>> code in html page:
>> 
>> open(FILE,"</path/to/file");
>> while(<FILE>) {
>>         print;
>> }
>> 
>> Could anybody help me?
>> 
>> T.I.A.
>> 
>> --
>> Ryszard �ach
>> Internet Designers s.c.
>> http://www.id.pl
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
>> For additional commands, e-mail: embperl-help@perl.apache.org
> 
> --
> __________________________________________________________
> Mr. Erich L. Markert                     emarkert@pace.edu
> Computer Learning Center               TEL (914)422-4328
> Pace University
> 1 Martine Ave
> White Plains, New York 10606-1932
> 
> Those who do not understand Unix are condemned to reinvent it, poorly.
>                 -- Henry Spencer
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
> For additional commands, e-mail: embperl-help@perl.apache.org

-- 
Jason Bodnar + jbodnar@team-linux.com + Team Linux

Homer:  I keep hearing this horrible irregular thumping noise.

Pump Jockey:
        It's your heart.  And I think it's on its last thump.

Homer:  Whew, I was afraid it was my transmission.

                   Homer's Triple Bypass


Re: Beginner's question

Posted by "Erich L. Markert" <em...@pace.edu>.
Try:

[-
open(FILE,"</path/file") || die "Can't open file";
$escmode = 0; # needed for the subsequent print in "while" 
	      # otherwise Embperl will complain
while(<FILE>){
	print;
}
$escmode = 1;
close(FILE);
-]

Ryszard Lach wrote:
> 
> Hi!
> 
> I've read docs about using embperl and HTML escaping, I tried to display e.g.
> forms data (it works fine),  but I still don't know, how to embedd such a simple
> code in html page:
> 
> open(FILE,"</path/to/file");
> while(<FILE>) {
>         print;
> }
> 
> Could anybody help me?
> 
> T.I.A.
> 
> --
> Ryszard £ach
> Internet Designers s.c.
> http://www.id.pl
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
> For additional commands, e-mail: embperl-help@perl.apache.org

--
__________________________________________________________
Mr. Erich L. Markert                     emarkert@pace.edu
Computer Learning Center		 TEL (914)422-4328
Pace University
1 Martine Ave
White Plains, New York 10606-1932

Those who do not understand Unix are condemned to reinvent it, poorly.
                -- Henry Spencer

RE: Beginner's question

Posted by jb...@team-linux.com.
On 14-Jun-2000 Ryszard Lach wrote:
> Hi!
> 
> I've read docs about using embperl and HTML escaping, I tried to display e.g.
> forms data (it works fine),  but I still don't know, how to embedd such a
> simple
> code in html page:
> 
> open(FILE,"</path/to/file");
> while(<FILE>) {
>       print;
> }
> 
> Could anybody help me?

[- open FILE, "/path/to/file" -]
[$ while <FILE> $]
 [+ $_ +]
[$ endwhile $]


-- 
Jason Bodnar + jbodnar@team-linux.com + Team Linux

Homer:  We always have one good kid and one lousy kid.  Why can't both 
        our kids be good?

Marge:  We have three kids, Homer.

                   Separate Vacations