[7923] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 1548 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Dec 29 19:07:21 1997

Date: Mon, 29 Dec 97 16:00:27 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 29 Dec 1997     Volume: 8 Number: 1548

Today's topics:
     Bug: 30 chars of perl uses 269MB! (Nick Andrew)
     Re: bug? (was: Bitwise XOR (^) doesn't work on strings? <jack_h_ostroff@groton.pfizer.com>
     CGI: system "cat... <maximill@u.washington.edu>
     Re: Complex shell pipes to perl? <david.x.corcoran@boeing.com>
     creating subclasses / HTML::Parser jsd@bud.com
     Re: extract using reg. expr (Sami Sandqvist)
     Re: Finding the TITLE to a HTML page (Abigail)
     Re: How would you do this... (John Stanley)
     Re: How would you do this... <reibert@mystech.com>
     named pipe help <jbattikha@highsynth.com>
     NT cgi query greg@unibiz.net
     PERL URL-Encoding <dustin@hub.ofthe.net>
     problem with strict (Tomas)
     Problems compiling perl w/ dynamic loading on AIX 4.1.5 <tmill06@ibm.net>
     Re: Size in KB <mhanson@arrowweb.com>
     Re: Sorting files <merlyn@stonehenge.com>
     Re: Which language pays most? Smalltalk, not C++ nor Ja (Kaz Kylheku)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 30 Dec 1997 10:02:48 +1100
From: nick@zeta.org.au (Nick Andrew)
Subject: Bug: 30 chars of perl uses 269MB!
Message-Id: <689a6o$ros$1@gidora.kralizec.net.au>

G'day,

While playing with embedding quotes in strings I hit a combination which
causes Pel 5.003 to run out of memory. In fact an strace showed it trying
to mmap() 1.2 gigs.

I shortened my program to 30 characters. It only tries to mmap 269 megs
now, but at least it is instructive:

#!/usr/bin/perl
$i='(\\'x\\''

Perhaps somebody can explain what Perl thinks it is doing; perhaps somebody
can fix whatever the bug is (probably a perplexing parser problem).

Nick.
-- 
Kralizec / Zeta Microcomputer Software  Fax: +61-2-9233-6545 Voice: 9837-1397
G.P.O. Box 3400, Sydney NSW 1043        http://www.zeta.org.au/


------------------------------

Date: Mon, 29 Dec 1997 15:19:04 -0500
From: "Jack H. Ostroff" <jack_h_ostroff@groton.pfizer.com>
To: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: bug? (was: Bitwise XOR (^) doesn't work on strings?)
Message-Id: <34A805B8.781A@groton.pfizer.com>

Tom Phoenix wrote:
> 
> Here's a doc patch to cover bitwise string operations. The examples are
> all ASCII-based due to my shortage of EBCDIC machinery.  :-)
> 
I am still unclear about one point in the last few paragraphs

> --- perl5.004_04/pod/perlop.pod.orig    Wed Nov  5 07:57:17 1997
> +++ perl5.004_04/pod/perlop.pod Thu Nov  6 08:30:58 1997
> @@ -145,7 +145,7 @@
>  to C<"-bareword">.
> 
>  Unary "~" performs bitwise negation, i.e., 1's complement.
> -(See also L<Integer Arithmetic>.)
> +(See also L<Integer Arithmetic> and L<Bitwise String Operators>.)
> 
>  Unary "+" has no effect whatsoever, even on strings.  It is useful
>  syntactically for separating a function name from a parenthesized expression
> @@ -300,15 +300,15 @@
>  =head2 Bitwise And
> 
>  Binary "&" returns its operators ANDed together bit by bit.
> -(See also L<Integer Arithmetic>.)
> +(See also L<Integer Arithmetic> and L<Bitwise String Operators>.)
> 
>  =head2 Bitwise Or and Exclusive Or
> 
>  Binary "|" returns its operators ORed together bit by bit.
> -(See also L<Integer Arithmetic>.)
> +(See also L<Integer Arithmetic> and L<Bitwise String Operators>.)
> 
>  Binary "^" returns its operators XORed together bit by bit.
> -(See also L<Integer Arithmetic>.)
> +(See also L<Integer Arithmetic> and L<Bitwise String Operators>.)
> 
>  =head2 C-style Logical And
> 
> @@ -1213,6 +1213,34 @@
>  expression represents so that the interpreter
>  won't have to.
> 
> +=head2 Bitwise String Operators
> +
> +Bitstrings of any size may be manipulated by the bitwise operators
> +(C<~ | & ^>).
> +
> +If the operands to a binary bitwise op are strings of different sizes,
> +B<or> and B<xor> ops will act as if the shorter operand had additional
> +zero bits on the right, while the B<and> op will act as if the longer
> +operand were truncated to the length of the shorter.
> +
> +    # ASCII-based examples
> +    print "j p \n" ^ " a h";           # prints "JAPH\n"
> +    print "JA" | "  ph\n";             # prints "japh\n"
> +    print "japh\nJunk" & '_____';      # prints "JAPH\n";
> +    print 'p N$' ^ " E<H\n";           # prints "Perl\n";
> +
> +If you are intending to manipulate bitstrings, you should be certain that
> +you're supplying bitstrings: If an operand is a number, that will imply
> +a B<numeric> bitwise operation. You may explicitly show which type of
> +operation you intend by using C<""> or C<0+>, as in the examples below.
> +
> +    $foo =  150  |  105 ;      # yields 255  (0x96 | 0x69 is 0xFF)
> +    $foo = '150' |  105 ;      # yields 255
> +    $foo =  150  | '105';      # yields 255
> +    $foo = '150' | '105';      # yields string '155' (under ASCII)
> +
> +    $baz = 0+$foo & 0+$bar;    # both ops explicitly numeric
> +    $biz = "$foo" ^ "$bar";    # both ops explicitly stringy
> 
>  =head2 Integer Arithmetic
> 
> @@ -1230,7 +1258,8 @@
>  which lasts until the end of that BLOCK.
> 
>  The bitwise operators ("&", "|", "^", "~", "<<", and ">>") always
> -produce integral results.  However, C<use integer> still has meaning
> +produce integral results.  (But see also L<Bitwise String Operators>.)
> +However, C<use integer> still has meaning
>  for them.  By default, their results are interpreted as unsigned
>  integers.  However, if C<use integer> is in effect, their results are
>  interpreted as signed integers.  For example, C<~0> usually evaluates

Do the bitwise logical operators ALWAYS produce integral results?  The
fourth
foo example implies that the result is string if both operands are
strings.

Also..... the comment on integral results might be expanded to say
what they do if the operands are not integral.  (My brief testing seems
to show it truncates to integer before applying the operator.)

Perhaps "The result of the bitwise operators (....) is a string if both 
operands are strings, otherwise the result is an integral number, the
operands being converted or truncated to integers first if necessary.
(See also ...)"

This is more explicit.  Also, hopefully "See also..." rather than "But
see
also..." is less confusing.

Jack Ostroff


------------------------------

Date: Mon, 29 Dec 1997 15:49:00 -0800
From: "B. Bell" <maximill@u.washington.edu>
Subject: CGI: system "cat...
Message-Id: <Pine.OSF.3.96.971229151337.8406D-100000@becker1.u.washington.edu>

i want to include a file in my cgi output.  I'm trying to use the system
function call to just 'cat' the file.
I suspect there's a far simpler solution?, but can anybody tell me why
this doesn't work:

call this program test.cgi:
--------------------------------------------
#!/usr/local/bin/perl
require "cgi-lib.pl";
print &PrintHeader;
print &HtmlTop("Test Script");
print "Included text below<br>\n";
system "cat includeme.html";
print "End of included text<br>\n";
print &HtmlBot;
---------------------------------------------

call this includeme.html:
---------------------------------------------
<h1>This is the Included Text</h1><br>
---------------------------------------------

now, we execute test.cgi:
---------------------------------------------
% ./test.cgi
Content-type: text/html
 
<html>
<head>
<title>Test Script</title>
</head>
<body>
<h1>Test Script</h1>
Included text below<br>
<h1>This is the Included Text</h1><br>
End of included text<br>
</body>
</html>
---------------------------------------------

just as one would expect, right?

but, if i try to access test.cgi over the web, I get a server error.
the badly formaatted error message looks something like this:
-----------------------------------------
malformed header from script. Bad
header=

This is the Included Text<
-----------------------------------------

in the trivial case, if i comment out this line:
#system "cat includeme.html";
There is no error, and I get
--------------------------
Test Script

Included text below
End of included text
--------------------------
over the web.

oh well, any hints?

-brad



------------------------------

Date: Mon, 29 Dec 1997 21:06:44 GMT
From: David Corcoran <david.x.corcoran@boeing.com>
Subject: Re: Complex shell pipes to perl?
Message-Id: <34A810E4.23B4@boeing.com>

Deepak Khosla wrote:
> 
> Hi,
> I have a complex 'application' written in ksh.
>...
> However, the primary purpose is to backup system files. 

you may want to check out this free disk archiver:

  http://www.leo.org/pub/comp/sysmgmt/backup/amanda/amanda.idx.html

I've installed it at a former employer's site, and though it didn't work
out of the box, it was a good deal better then rolling my own.

 > Q3) Is perl the right choice for this type of app? soemone want to
port it
> for me for a price? :-)

I may consider it. What are your time constraints and your target
machine?

--@@
   ~
DavidC


------------------------------

Date: Mon, 29 Dec 1997 15:21:30 -0600
From: jsd@bud.com
Subject: creating subclasses / HTML::Parser
Message-Id: <883430236.1317666823@dejanews.com>

I'm trying to use HTML::Parser to spit out HTML comments.  The perldoc
for it says:

       In order to make the parser do anything interesting, you
       must make a subclass where you override one or more of the
       following methods as appropriate

and then:

       $self->comment($comment)
           This method is called as comments are recognized.  The
           leading and trailing "--" sequences have been stripped
           off the comment text.

so i wrote this script:

#!/usr/local/bin/perl -w

require HTML::Parser;

open(FILE,"<$ARGV[0]");
undef $/;
$html=<FILE>;
close(FILE);

sub comment {
  print "hi there i'm alive\n";
  print @_;
}

$p = HTML::Parser->new;
$p->{'comment'} = \&comment;
$p->parse($html);
exit;


but it doesn't do anything.  it never prints "hi there i'm alive" so i'm
guessing that i'm not properly creating the subclass.  if i just say
$p->comment = \&comment i get "Can't modify subroutine entry in scalar
assignment."  if i take out all the messing with $p->comment and instead
put

sub HTML::Parser::comment {
  print "hi i'm alive\n";
}

I get a warning: "Subroutine comment redefined at
/usr/local/lib/perl5/site_perl/HTML/Parser.pm line 355" and nothing
happens.

i read perlobj, perlref and perltoot (particularly the "overriding
methods" page) but i am just Not Getting It.  the faq says to just read
perltoot, so i'm stuck in a loop there.

-j-

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet


------------------------------

Date: 29 Dec 1997 23:08:30 GMT
From: samiss@cc.tut.fi (Sami Sandqvist)
Subject: Re: extract using reg. expr
Message-Id: <slrn6agbbe.t6.samiss@ehdo.ton.tut.fi>

On Mon, 29 Dec 1997 10:33:15 -0600, p.babu@giasmd01.vsnl.net.in wrote:
>I am facing a couple of problems with regular expressions. I am unable to
>find a good tutorial on regular expressions.

Have you read the perlre man page?

>Is it possible to print out email address alone using a single expression?

Yes and no. A good regex for it exists, but it is _very_ long. The
solution below may be what you want.

>To put it in a simple way, I want to scan a line of text for the
>occurrence of '@' character and retrieve all the characters before and
>after the '@' till the occurrence of white space or ":" or "\"". Is it
>possible to do it using a single reg. expression?

Here you are. I have included some extra code with your sample cases
in case you are a beginner. Note the addition of a \ on the third
line.. Using $& and friends is not good, because they need to make a
copy of the original string.

-------------------------
#!/bin/perl -w
$str = 'Hello <a href="mailto:samy@ppp.com">mail me</a>';
$str2 = "Hello : E-Mail : cyrus\@cytel.com <BR>";
if ($str =~ /([^\s":]+@[^\s":]+)/){ 
    print "$1\n";
}
if ($str2 =~ /([^\s":]+@[^\s":]+)/){ 
    print "$1\n";
}
-------------------------

Sami
-- 
Sami Sandqvist - samiss@cc.tut.fi
Finger for PGP key.


------------------------------

Date: 29 Dec 1997 20:51:03 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Finding the TITLE to a HTML page
Message-Id: <slrn6ag3cr.50c.abigail@betelgeuse.wayne.fnx.com>

Joseph N. Hall (joseph@5sigma.com) wrote on 1581 September 1993 in
<URL: news:34A72A49.301320@5sigma.com>:
++ Tushar Samant wrote:
++ > 
++ > john@castleamber.com writes:
++ > >Eric Bohlman <ebohlman@netcom.com> wrote
++ > >
++ > >> <HTML>
++ > >> <HEAD>
++ > >> <TITLE>
++ > >> <!--Insert the title of the document after this
++ > >>   line but before the line that says </TITLE>-->
++ > >> </TITLE>
++ > >> ...
++ > >
++ > >weblint warns agains the use of mark up in comments. It is bad practice
++ > >to do so.
++ > 
++ > That's hardly the point... Take out the markup and you still have
++ > a counterexample. 
++ 
++ A comment inside <TITLE></TITLE> is a counterexample?  Well,
++ get rid of it then.

That's a nice way of dealing with programming issues. Just get rid
of any situation in which your program doesn't run.

++ > Why is it bad practice to have markup inside
++ > comments, though? This is not a Perl question, but I am curious,
++ > and asking a sincere question. What possible use can comments have
++ > with a restriction like that?
++ > 
++ 
++ The point is, HTML is hard and slow to parse, and
++ anything that makes it easier to do a "good enough" job 
++ is worthwhile.
++ 
++ This is probably not a direction I should go, but when
++ I hear people arguing that such-and-such a program doesn't
++ parse all HTML perfectly, I often get the feeling the argument
++ is more about someone's infatuation with the grandeur of
++ SGML and not about the needs of a programmer trying to
++ deal with a few plain old HTML files.  Only a very few
++ applications need to deal with *any possible* HTML file.
++ Others have simpler requirements.

That's a cause and result argument. Many HTML files have to be simple,
because the tools out are written by brainless programmers. If programmers
dealing with HTML would bother to think half a minute, we could have
fully used the potentials of HTML. But as long as we have simplistic
programmers, we'll have simplistic HTML documents.

++ All that aside, if someone eventually whips up a fast
++ HTML (or SGML) parser with an easy to use interface (I don't
++ think the current modules are there yet), I'll be all for it.
++ But HTML is so convoluted and has so many subtleties that
++ I have my doubts about whether an efficient, user-friendly 
++ HTML parser will come to pass.

There are many general SGML parsers out there that fully parse HTML. As
far as I know, SGML is a context free grammer, probably LL(1). I really
fail to see why parsing HTML has to be slow.

Now, parsing HTML using Perl RE's might be slow, but that's a different
matter and has nothing to do with HTML itself.



Abigail
-- 
perl -wle 'print "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/'


------------------------------

Date: 29 Dec 1997 20:25:28 GMT
From: stanley@skyking.OCE.ORST.EDU (John Stanley)
Subject: Re: How would you do this...
Message-Id: <6890vo$ivp$1@news.orst.edu>

In article <34A7EBBE.4643BC7E@mystech.com>,
Mark S. Reibert <reibert@mystech.com> wrote:
>Sorrow wrote:
>
>> and what it is supposed to do is sort the information
>> in the original text file based on DATA2 and write it
>> out to a new, sorted, text file.

The code you provided does not do what the story problem wants. The code
appears to put every line where DATA2 is 1 at the front of the new file,
with the other lines following. Is this what you wanted, or did you
really want to sort the file on DATA2? 

>Hmmm, sounds like everyone is missing the value of a hash! How 'bout this:
>
>%info = ();
>while ( <> ) {
>  my $key = split( /\s+/, $_ )[1];
>  $info{$key} = $_;
>}

The problem did not limit the uniqueness of DATA2. If there is more
than one line where DATA2 has a certain value, the hash solution will
throw away all but the last line it finds. In fact, the original code
implies multiple lines where DATA2 == 1.  It also seems like a little
overkill, creating all the hashed entries when a simple array would
have sufficed.

My solution? 

	sort -n +1 <input >output

What remains unspecified in the original problem is how the lines with
duplicate DATA2 values should be sorted. 



------------------------------

Date: Mon, 29 Dec 1997 15:18:22 -0700
From: "Mark S. Reibert" <reibert@mystech.com>
Subject: Re: How would you do this...
Message-Id: <34A821AE.6B49036@mystech.com>

John Stanley wrote:

> The code you provided does not do what the story problem wants. The code
> appears to put every line where DATA2 is 1 at the front of the new file,
> with the other lines following. Is this what you wanted, or did you
> really want to sort the file on DATA2?
>
> >Hmmm, sounds like everyone is missing the value of a hash! How 'bout this:
> >
> >%info = ();
> >while ( <> ) {
> >  my $key = split( /\s+/, $_ )[1];
> >  $info{$key} = $_;
> >}
>
> The problem did not limit the uniqueness of DATA2. If there is more
> than one line where DATA2 has a certain value, the hash solution will
> throw away all but the last line it finds. In fact, the original code
> implies multiple lines where DATA2 == 1.  It also seems like a little
> overkill, creating all the hashed entries when a simple array would
> have sufficed.
>
> My solution?
>
>         sort -n +1 <input >output
>
> What remains unspecified in the original problem is how the lines with
> duplicate DATA2 values should be sorted.

Fair enough! I shot back a quick answer w/o considering multiple entries in the
DATA2 column :-(
For what it's worth, I was equally confused about the original post comparing
to 1 - didn't agree with the stated desire to sort!

As for your solution, great if one is on UNIX, but many persons on this NG are
Windows based. NT has a command-line sort routine, but I'm not sure if Windows
4 (er, uh, 95) does.

-----------------------------
   Mark S. Reibert, Ph.D.

  Mystech Associates, Inc.
  3233 East Brookwood Court
   Phoenix, Arizona 85044

    Tel: (602) 732-3752
    Fax: (602) 706-5120
 E-mail: reibert@mystech.com
-----------------------------




------------------------------

Date: Mon, 29 Dec 1997 16:51:39 -0500
From: Jihad Battikha <jbattikha@highsynth.com>
Subject: named pipe help
Message-Id: <34A81B6B.D28624B8@highsynth.com>

This is a multi-part message in MIME format.
--------------BBE8F530BC2E8983791F2AD3
Content-Type: text/plain; charset=us-ascii
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Transfer-Encoding: 7bit

Hello all,

Please forgive my "newbieness" if I sound confused here...

I'm trying to create a _temporary_ named pipe that will fool another
program into thinking it's accessing data from a real file.  Once all
the data has been read, the named pipe should disappear...I don't want
it to hang around or leave any zombie processes.  I know how to create
the named pipe (on Unix) and delete it when I'm done, but I'm having
trouble conceiving of a way to have the pipe accessed by an external
program (since the main script has to "stall" waiting for an access
request to the pipe) -- since this is 1)a temporary pipe & 2)I want to
have it accessed almost immediately after it's created,  I know I need
to create some sort of child process but I've never done it before & I'm
having a hard time with the facts & docs (& books).  The timing of the
processes is also critical, since i don't want the child process to
start reading until the named pipe is "blocked" by the main/parent
script.

The reason I need to use a named pipe instead of STDIN is because I'm
trying to compress multiple (appended) entries into a single file with
PGP and unless PGP is compressing from an actual file, all the
compressed "file names" PGP stores end up being named 'STDIN'.  I can't
write out a temporary *REAL* file since I don't want to store sensitive
data unencrypted even temporarily on a remote server that hosts my
site.  I do, however, need to name the files something descriptive since
I need to retrieve the single file (with multiple entries) and
decompress its contents without having all the entries overwrite
themselves (since they'd all be named 'STDIN').

I also would like to make this work in an NT environment for testing
(although I'm not sure what the equivalent of 'mnknod' or 'mkfifo' is on
NT) -- having this run on NT would be very helpful.

Here's what I have so far (a lot of nested if statements...sorry):
[I also attached the script...]

---- start code ----
#!/usr/bin/local/perl -w

chdir;
$FIFO = "$ENV{DOCUMENT_ROOT}/temp/tempfile.tmp";
$ENV{PATH} .= ":/etc:/sbin:$ENV{DOCUMENT_ROOT}/temp";
$data2enc = "This is the text we need to encrypt...grabbed from STDIN.";

$temp_encrypt_file = "$ENV{DOCUMENT_ROOT}/temp/temp_enc.tmp"; # need
this, since PGP won't use STDOUT without STDIN
$final_file = "$ENV{DOCUMENT_ROOT}/temp/maindata.txt";

$proc_id = fork;
if ($proc_id == 0) { # CHILD
  while (1) {
        unless (-p $FIFO) {
          unlink $FIFO;
          # I can't use exec here since I want a continuos block on
$FIFO
          system('mknod', $FIFO, 'p') || die "Can't mknod $FIFO: $!\n";
        }
    open (FIFO, "> $FIFO") || die "Can't write to $FIFO: $!\n";
    print FIFO "$data2enc";
    close(FIFO);
    sleep(2); # do I need this?
  }
}
elsif (defined $proc_id) { # PARENT
  sleep(4); # is this dependable? - I need to be sure child has done
it's duty first
  # well, let me verify the $FIFO then...
  $waittime = 20;
  $waittime = time + $waittime;
      while (-e $FIFO eq "" && time < $waittime) {
        # do nothing? - just wait...
      }
  $pgp = "$ENV{DOCUMENT_ROOT}/apps/pgpe";
  $pgpid = "account\@domain.com";
  $pubring = "$ENV{DOCUMENT_ROOT}/apps/pgp/pubring.pkr";
  # whatever the commandline needs to be...
  # will probably fail if $FIFO still doesn't exist after 24+ seconds
(long time...)
  open(PGP,"| $pgp -r $pgpid -aft --pubring=$pubring -o
$temp_encrypt_file $FIFO") || die "PGP failed: $!\n";
  close(PGP);
      if ($proc_id == 0) { # SWITCH TO CHILD AND KILL IT
        exit(0); # will this kill the child and its loop?
        unlink $FIFO;
        # $exitfifo = `rm $FIFO`; # would this be better?
      }
  $died = $pid; # get pid from parent
  $pid = wait; # get pid of child (should now be dead)
      # should I use 'eq' here? result can be (1) or ("")
      if ($pid == $died) { # CHILD IS DEAD & WE'RE BACK IN THE PARENT
         $result = "Child has died.\nFIFO exit results (if used \"rm
\$FIFO\"): $exitfifo\n";
      }
      else {
        $result = "Child lives?.\nFIFO exit results (if used \"rm
\$FIFO\"): $exitfifo\n";
      }
}
else {
  die "Fork error: $!\n";
}

open(FINALFILE, "<$final_file") || die "Can't open $final_file: $!\n";
open(TEMPFILE, ">>$temp_encrypt_file") || die "Can't open
$temp_encrypt_file: $!\n";
while (<TEMPFILE>) {
  print FINALFILE $_;
}
close(FINALFILE);
close(TEMPFILE);
print "Here are the results...\n$result";
exit;
---- end code ----

Sloppy, I know...

Any help would be appreciated.  I think maybe I could reverse the
actions and have the PGP action run in the child, but then I don't know
how I would exit the loop in the parent.  Perhaps a signal would be
better in that instance?  I don't know much about signals...

Also, a tricky part is making sure that the child has created the $FIFO
file & is blocking it before the parent attempts to access it.  Is there
a fool-proof way to do this or is anything I do here a risk?

I keep getting an "internal server error" -- the syntax is OK, so I'm
probably not doing this right.  I don't have direct shell access to the
server (only CGI-BIN access) so it's hard to debug this thing and since
I'm not adept enought yet to port it to NT, I'm kinda stuck.

Oh, yeah, here's the breakdown on the server configuration (just in case
it's helpful):
SGI Origin200/ChallengeS Server
IRIX V6.4
Apache V1.2

Obviously, I'm not running as root.  I don't think my scripts run as
'nobody', I'm pretty sure they run under my user id on the system.
Anyway, like I said above, none of this code is dependent on CGI other
than the way I access/debug it.  That's not the issue.  The issue is how
I'm trying to deal with the process/pipe handling...

--
Jihad Battikha
jbattikha@highsynth.com
http://www.highsynth.com


--------------BBE8F530BC2E8983791F2AD3
Content-Type: application/x-perl; name="n_pipe.pl"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="n_pipe.pl"

#!/usr/bin/local/perl 

chdir; 
$FIFO = "$ENV{DOCUMENT_ROOT}/temp/tempfile.tmp"; 
$ENV{PATH} .= ":/etc:/sbin:$ENV{DOCUMENT_ROOT}/temp"; 
$data2enc = "This is the text we need to encrypt...grabbed from STDIN."; 
$temp_encrypt_file = "$ENV{DOCUMENT_ROOT}/temp/temp_enc.tmp"; # need this, since PGP won't use STDOUT without STDIN 
$final_file = "$ENV{DOCUMENT_ROOT}/temp/maindata.txt"; 

$proc_id = fork; 
if ($proc_id == 0) { # CHILD 
  while (1) { 
        unless (-p $FIFO) { 
          unlink $FIFO; 
          # I can't use exec here since I want a continuos block on $FIFO 
          system('mknod', $FIFO, 'p') || die "Can't mknod $FIFO: $!\n"; 
        } 
    open (FIFO, "> $FIFO") || die "Can't write to $FIFO: $!\n"; 
    print FIFO "$data2enc"; 
    close(FIFO); 
    sleep(2); # do I need this? 
  } 
} 
elsif (defined $proc_id) { # PARENT 
  sleep(4); # is this dependable? - I need to be sure child has done it's duty first 
  # well, let me verify the $FIFO then... 
  $waittime = 20; 
  $waittime = time + $waittime; 
      while (-e $FIFO eq "" && time < $waittime) { 
        # do nothing? - just wait... 
      } 
  $pgp = "$ENV{DOCUMENT_ROOT}/apps/pgpe"; 
  $pgpid = "account\@domain.com"; 
  $pubring = "$ENV{DOCUMENT_ROOT}/apps/pgp/pubring.pkr"; 
  # whatever the commandline needs to be... 
  # will probably fail if $FIFO still doesn't exist after 24+ seconds (long time...)
  open(PGP,"| $pgp -r $pgpid -aft --pubring=$pubring -o $temp_encrypt_file $FIFO") || die "PGP failed: $!\n"; 
  close(PGP); 
      if ($proc_id == 0) { # SWITCH TO CHILD AND KILL IT 
        exit(0); # will this kill the child and its loop? 
        unlink $FIFO; 
        # $exitfifo = `rm $FIFO`; # would this be better? 
      } 
  $died = $pid; # get pid from parent
  $pid = wait; # get pid of child (should now be dead)
      # should I use 'eq' here? result can be (1) or ("")
      if ($pid == $died) { # CHILD IS DEAD & WE'RE BACK IN THE PARENT 
         $result = "Child has died.\nFIFO exit results (if used \"rm \$FIFO\"): $exitfifo\n"; 
      } 
      else { 
        $result = "Child lives?.\nFIFO exit results (if used \"rm \$FIFO\"): $exitfifo\n"; 
      } 
} 
else { 
  die "Fork error: $!\n"; 
} 

open(FINALFILE, "<$final_file") || die "Can't open $final_file: $!\n"; 
open(TEMPFILE, ">>$temp_encrypt_file") || die "Can't open $temp_encrypt_file: $!\n"; 
while (<TEMPFILE>) { 
  print FINALFILE $_; 
} 
close(FINALFILE); 
close(TEMPFILE); 
print "Here are the results...\n$result"; 
exit; 

--------------BBE8F530BC2E8983791F2AD3--



------------------------------

Date: Mon, 29 Dec 1997 13:51:34 -0600
From: greg@unibiz.net
Subject: NT cgi query
Message-Id: <883424387.1036320769@dejanews.com>

Trying to use a HREF tag in html to access a cgi script with a query
string on an NT server -- NT ignores the question mark separating the cgi
script from the query string and returns a cgi error.  Any hints?

<A HREF="links.pl?variableXYZ">

causes:

CGI Error The specified CGI application misbehaved by not returning a
complete set of HTTP headers. The headers it did return are:

Can't open perl script "C:\Perl\bin\links.plvariableXYZ": No such file or
directory

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet


------------------------------

Date: Mon, 29 Dec 1997 14:25:41 -0600
From: Dustin Arnold <dustin@hub.ofthe.net>
Subject: PERL URL-Encoding
Message-Id: <34A80745.14F83A7@hub.ofthe.net>

Could anyone email me the line(s) of PERL that would re-URLencode a
string
of text (do the opposite of this):

$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

Thanks in advance,
Dustin Arnold
da@lubbock.net





------------------------------

Date: Mon, 29 Dec 1997 21:36:40 GMT
From: tomas@iimagers.com (Tomas)
Subject: problem with strict
Message-Id: <68955l$djq$1@gte1.gte.net>

I am going nuts...I cannot understand why the following scripts
returns the following error:

Bareword "FILE" not allowed while "strict subs" in use at
company_upload.cgi line 8.
company_upload.cgi had compilation errors.  

--------------------------------------
#!/usr/local/bin/perl -w

use strict;
use CGI;

my $filename = "setup.dat";
open (FILE, ">" . "$filename");
my $query->save(FILE);
close (FILE);           
---------------------------------------

Any help is greatly appreciated.

Tomas



------------------------------

Date: 29 Dec 1997 14:10:47 -0600
From: Timothy Miller <tmill06@ibm.net>
Subject: Problems compiling perl w/ dynamic loading on AIX 4.1.5 & 4.2.0.
Message-Id: <wkius7kj08.fsf@ibm.net>


	Perl tests successfully without dynamic loading, but no matter
what I've tried so far when compiling with dynamic loading enabled it
fails at test 0 on 22 tests.  This is happening on 4.1.5 and 4.2.0.

	Any helpful hints?

-- 
Cerebus <tmill06@ibm.net>



------------------------------

Date: Mon, 29 Dec 1997 17:21:26 -0800
From: Mike <mhanson@arrowweb.com>
Subject: Re: Size in KB
Message-Id: <34A84C96.590A@arrowweb.com>

John Bokma wrote:
> 
> brian d foy <comdog@computerdog.com> wrote in article
> <comdog-2912970551260001@news.panix.com>...
> > In article <34A721AF.3D40@arrowweb.com>, mhanson@arrowweb.com wrote:
> >
> > > How do you tell the size of a string in KB. I have a string that is the
> > > contents of a file and i want to beable to tell how large it is before
> i
> > > save it to my server.
> >
> > count how many characters are in the string (perhaps with length() ),
> > multiply by the number of bytes per character, then divide by 1000.
> 
> 1024 8-).
> 
> > or check the file size for the file (perhaps with a file test
> > operator) from which the data came.
> 
> If you do this on a dos/windos/nt machine, take care of the line
> termination, which
> differs from UNIX.
> 
> John
> 
> --
> ------------------------------------------------------------------
> C A S T L E  A M B E R      Software Development (Java/Perl/C/CGI)
> http://www.castleamber.com/ john@castleamber.com


How exactly do i use the length()? Say may variable is $stuff Also you
said multiply it by the number of bytes per character but how many bytes
are there per charater? Also then i divide by 1024 right?


------------------------------

Date: 29 Dec 1997 15:00:48 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: jdporter@min.net
Subject: Re: Sorting files
Message-Id: <8c67o795db.fsf@gadget.cscaper.com>

>>>>> "John" == John Porter <jdporter@min.net> writes:

John> Randal Schwartz wrote:
>> Now, if it's more than about 20 names or so, you should step up to
>> a Schwartzian Transform (or some other technique).  See examples
>> of this in my "sorting" column from UnixReview at:
>> 
>> http://www.stonehenge.com/merlyn/UnixReview/

John> Randal,
John> I looked at this file (col06.html), and found no mention of anything
John> called a Schwartzian (or any other kind of) Transform.
John> What technique specifically did you mean to refer to by this name?

The column doesn't call it that because (a) I didn't invent the name,
although it was named after me and (b) the column was written before
the name was assigned.

print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,990.69 collected, $186,159.85 spent; just 245 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


------------------------------

Date: 29 Dec 1997 20:05:31 GMT
From: bill@cafe.net (Kaz Kylheku)
Subject: Re: Which language pays most? Smalltalk, not C++ nor Java.
Message-Id: <688vqb$k9q$1@brie.direct.ca>

In article <34A812F9.C169A703@its.cl>,
Guillermo Schwarz  <gschwarz@its.cl> wrote:
>It's nice to know C advances so fast I can't keep up to date with its
>definition."Reserved as identifiers" is something meaningful to you? Can you
>reserve a name as
>a non indentifier?

No, but you can reserve a name for use as one kind of identifier but not
another. ``Reserved for external linkage'' means that your program cannot
define certain identifiers such that these identifiers have external
linkage. 

It means that you can still use 'memcpy' as the name of a local variable, 
as a typedef name, or as a name with internal linkage or a macro name.
(However, if you use the name in these ways, you may not include the
<string.h> header in the translation unit because such uses may clash
with that header.)

>"with external linkage"? Those are too many words just to mean an extrernal
>name.

The term ``external name'' is a short way of saying ``name with external
linkage''. What's the big deal about that?

>The point is, at least when I studied the good and old K&R, it didn't mention
>
>"reserved as identifiers with external linkage", that for me means "don't
>touch this,

Note that what is now the library was not yet a formal part of the language
then.  The standard C library had its beginnings as an actual UNIX library.

Anyway, K&R1 did _not_ bless any program which has multiple definitions
of external names! 

The library is a required component of a hosted implementation of modern,
standard C. Thus it follows that its external names are off-limits
to the programmer who wishes to write strictly conforming C code,
or come as close as possible.

>or trick"... The C guys modify their language each 3 months just when they
>realize
>something is missing. If you think it is funny, I think it is pretty messy.

Nonsense. The standard has been stable for 8 years now, with only very
minor changes in response to genuine defect reports, the addition of
one header file <iso646.h> and support for wide character I/O. Prior
to the standard, the C language was in shambles.

The big changes are coming in C9X, which will be a distinct language from
1989 C.

>In Smalltalk, there is USUALLY no need to change the language, but just the
>need
>to add new classes and methods to achieve what's needed.

Are you talking about an implementation of Smalltalk or the language
Smalltalk? Based on your previous posting, it's obvious that you confuse
the two.

How do you add these new methods and classes to the *language*? That would
require that you join some committee and push for the changes to be
added to the language definition.

If what you mean is that you can add some classes to your Smalltalk
programming environment, then so what? You can also add your own libraries
to a C project, or classes to a C++ project.


------------------------------

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V8 Issue 1548
**************************************

home help back first fref pref prev next nref lref last post