[18882] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1050 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jun 3 21:05:32 2001

Date: Sun, 3 Jun 2001 18:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <991616709-v10-i1050@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sun, 3 Jun 2001     Volume: 10 Number: 1050

Today's topics:
    Re: Complex Parser... (Chris Fedde)
        Configuring Mod_perl on Windows <AHALL5@nc.rr.com>
    Re: Excluding certain output variables? <goldbb2@earthlink.net>
    Re: Flame Target (E.Chang)
    Re: Frustrated people (not) answering questions <newspost@coppit.org>
    Re: getpwnam - Unimplemeted Function <Juha.Laiho@iki.fi>
        help with hashes <smarshal@attcanada.ca>
    Re: help with hashes <bart.lateur@skynet.be>
        Help with the $0 equivalent, portable for use in DOS/Wi (codeslayer)
    Re: Help with the $0 equivalent, portable for use in DO <bart.lateur@skynet.be>
    Re: mailing from perl <goldbb2@earthlink.net>
    Re: My multi upload script isnt working right... <rsherman@ce.gatech.edu>
    Re: Newbie trends over time <newspost@coppit.org>
    Re: perl/cgi and dynamic hyperlink (krakle)
    Re: perl/cgi and dynamic hyperlink (E.Chang)
        PlRPC causing trouble with STDIN/OUT <abaugher@esc.pike.il.us>
    Re: readline  is strange on WinNT <goldbb2@earthlink.net>
    Re: Recursing a directory tree <goldbb2@earthlink.net>
    Re: using perl with msaccess <stuart@otenet.gr>
    Re: using perl with msaccess <bart.lateur@skynet.be>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 04 Jun 2001 00:26:51 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: Complex Parser...
Message-Id: <fBAS6.368$E_i.199910912@news.frii.net>

In article <3B1952A7.48FEA5A5@jagas.demon.co.uk>,
Joe B  <joeb@jagas.demon.co.uk> wrote:
>Hello All,
>
> select * from table WHERE MATCH col1
> AGAINST('(London South-West Midlands  Telework) +(Solaris Sun) +(awk
> C DHCP Ethernet HP-UX HPUX JumpStart Korn Legato
>shellscript TCP UNIX) ~(Permanent "1st Line" Programmer
>DBA "First Line" Helpdesk Junior Operator Tester "Test
>Analyst" "Test Engineer")')
>AND NOT col1 LIKE '%1st Line%'
>AND col1 LIKE '"First Line"';
>

It is highly unlikely that the average user will enter such complex
query structure or if they try that the syntax will be correct.
I'd try to side step the issue by taking one of two approaches.
One would be to allow the user to simply enter the text in a format
that may be handed directly to the database engine, and hand SQL
parser errors back to the user with their text so that they can
correct it.  The other is to design a set of pick lists and radio
buttons so that impossible queries cannot be generated.  Then compose
the query with suitable concatenation of separate form fields.

chris
-- 
    This space intentionally left blank


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

Date: Mon, 04 Jun 2001 00:41:40 GMT
From: "Antoine Hall" <AHALL5@nc.rr.com>
Subject: Configuring Mod_perl on Windows
Message-Id: <8PAS6.124034$Pp1.32572861@typhoon.southeast.rr.com>

I have intalled Apache on my windows machine and I want to run Mod_perl but
I cannot seem to configure it correctly.  Does anyone have easy setup steps
to do this on a windows machine?  I have done it on a linux machine before,
but I do not know what to do on the windows machine.

Thanks

AE







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

Date: Sun, 03 Jun 2001 20:26:05 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Excluding certain output variables?
Message-Id: <3B1AD59D.4D6E6A6F@earthlink.net>

David Soming wrote:
> 
> Hi new to perl,
> I have this script which displays SSI environment variables in browser:
>   #!/usr/local/bin/perl
>    print "Content-type: text/html\n\n";
>    print "<tt>\n";
>    foreach $key (sort keys(%ENV)) {
>       print "$key = $ENV{$key}<p>";
>    }
> 
> Using: <!--#exec cgi="cgi-bin/ALL_ENV.cgi"-->
> 
> How can I exclude specific variables in the output namely;
> UNIQUE_USER_ID=
> REDIRECT_UNIQUE_ID=
> REDIRECT_USER_NAME=
> What do I need to do to exclude these? Any suggestions what I need to read
> up on please?
> Thanks very much.

Well, here's one way:

foreach my $key (sort grep !/^(
	UNIQUE_USER_ID | REDIRECT_UNIQUE_ID | REDIRECT_USER_NAME
	)$/x keys(%ENV))
{
	print "$key = $ENV{$key}<br>";
}

Here's another:
@::ENVSTUFF = qw(UNIQUE_USER_ID REDIRECT_UNIQUE_ID REDIRECT_USER_NAME);

my ($id,$rid,$rname) = @ENV{@ENVSTUFF}; delete @ENV{@ENVSTUFF};

foreach my $key (sort keys %ENV) {
	print "$key = $ENV{$key}<br>";
}

-- 
The longer a man is wrong, the surer he is that he's right.


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

Date: Mon, 04 Jun 2001 00:02:01 GMT
From: echang@netstorm.net (E.Chang)
Subject: Re: Flame Target
Message-Id: <Xns90B5CC3AD84C7echangnetstormnet@207.106.93.86>

"Godzilla!" <godzilla@stomp.stomp.tokyo> wrote in 
<3B1AA0E6.67088C71@stomp.stomp.tokyo>:

[snip]

>Doesn't matter if a SSI called script is a typical .cgi script.
>Without at least a partial header print, an error log entry will
>be generated, at least under an Apache server. Nonetheless, 
>data is returned correctly. For these circumstances, all
>header prints can be excluded without effecting operation.
>
>Test this if you wish to observe this behavior.
>

Tested as follows:

The SSI document
  <html><body>
  <!--#include virtual='/~echang/cgi-bin/hello.cgi' -->
  </body></html>

The script 
  #!/usr/bin/perl
  #print "Content-Type: text/plain\n\n";
  print "Hello out there, world!";

The result with Content-type header
  Hello out there, world! 

The result without Content-type header (commented out)
  [an error occurred while processing this directive] 

SERVER_SIGNATURE     
Apache/1.3.9 Server at www.netstorm.net Port 80

-- 
EBC


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

Date: Sun, 3 Jun 2001 20:21:20 -0400
From: David Coppit <newspost@coppit.org>
Subject: Re: Frustrated people (not) answering questions
Message-Id: <Pine.SUN.4.33.0106032016470.1102-100000@mamba.cs.Virginia.EDU>

On Fri, 1 Jun 2001, Godzilla! wrote:

> > Matt's code created a horrendous support burden on this
> > newsgroup and for many other Perl people, as well as quite
> > a bit of frustration on the part of his users.  i don't
> > consider that a better world.

[snip champagne]

> Dealing with Matt's early efforts at providing free
> Perl scripts for all, has taught a lot of people,
> a lot about Perl. Our Perl community is better off
> thanks to Matt and his sincere efforts to provide
> free scripts for any and all.

Agreed. Matt's code, although it may offend the asthetics of many Perl
aficiando's, gets the job done. That's all most of his "customers"
care about. AFAIK, most critics of his work don't provide any
alternative, or even offer to help him update his code to help reduce
the support burden.

On the other hand, you'd expect Matt to update his own code as he
learns more Perl. :)

David



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

Date: 3 Jun 2001 06:37:37 GMT
From: Juha Laiho <Juha.Laiho@iki.fi>
Subject: Re: getpwnam - Unimplemeted Function
Message-Id: <9fclvh$uc7$1@ichaos.ichaos-int>

"KeysDigital" <shmink@keysdigital.com> said:
>I'm trying to get a script running on an NT maching running IIS and Perl
>5.6. The code I'm having a problem with is as follows:
>
>sub CheckLogin {
>   if (kDebugLevel >= kShowSubroutines) { print STDERR "CheckLogin - \n"; }
>   (my $name, my $passwd) = getpwnam($userlogin);
>   if ($passwd ne "") {
> if (crypt(&Obscure($userpassword), kEncryptedPassword) eq
>kEncryptedPassword) {
>           $cgi->delete("userlogin");
>           $cgi->delete("userpassword");
>     return 1;
> }
>    }
>   $cgi->delete_all();
>    return 0;
> }

So apparently there is no getpwnam implementation for NT.
getpwnam is an Unix API call to get information on a single OS level user;
if, in the above, you want to authenticate users against your NT (local
or domain) user accounts, you should use some NT-specific calls for that
(I don't have experience in programming perl on NT so I cannot tell what
functions you might need).

Alternatively you might roll your own implementation of something like
the htpasswd files, which are in the form loginname:passwordhash . So,
someone tries to log in with name 'joe' and password 'xyzzy', you go
through the password file looking for a line for 'joe'. Then you read
the password hash of that line; run the given password and the retrieved
hash through the crypt function (like you do above), and compare the
result to the stored password hash. If what you get out of crypt match
with the stored hash, the password given by 'joe' was correct.


About the code above, I'd claim that the call to 'Obscure' above is
superfluous and with some bad luck might even degrade security.
I see two possibilities:
- Obscure is two-way function (like rot13; you can always retrieve the
  original string when you have the obscured one); no increase in security
- Obscure is one-way function (like crypt; you run into risk that the
  obscured passwords cover only a subset of all possible passwords, and
  knowing how Obscure works might help an attacker to create passwords
  to only attack this subset)

Of course it is  also possible, that obscure contains some secure one-way
hash, which improves security, but then the crypt becomes superfluous;
there shouldn't be need for going through two one-way hashes. So, crypt()
is a bit misnamed; it doesn't encrypt, it calculates a hash value. From
the hash value there's no direct way back -- you can only try dictionary
attacks and systematic brute force methods to break crypt()ed passwords.
-- 
Wolf  a.k.a.  Juha Laiho     Espoo, Finland
(GC 3.0) GIT d- s+: a C++ UH++++ UL++++$ P++@ L+++ E(-) W+$@ N++ !K w !O
         !M V PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h--- r+++ y+++
"...cancel my subscription to the resurrection!" (Jim Morrison)


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

Date: Sun, 3 Jun 2001 19:44:44 -0400
From: "Steve Marshall" <smarshal@attcanada.ca>
Subject: help with hashes
Message-Id: <gZzS6.32624$TW.163480@tor-nn1.netcom.ca>

Howdy!
I am trying to parse a text file where I can pull out identical header lines
that are repeated throughout the file. I also want to retrieve two
additional lines (Hello and Goodbye) within each record.

Ex.
>blahblah
junk
junk
Hello
Goodbye
>blahblah
junk
junk
Hello
Goodbye
>blahblah
junk
junk
Hello
Goodbye

This is my code. I can pull out the header but I'm having trouble getting
the Hello and Goodbye lines.

#!/usr/local/bin/perl -w
use strict;
my %seen;

my $file = $ARGV[0];
open IN, $file or die "cannot open \"$file\": $!";

while (my $line = <IN>) {

     if ($line =~ /^>gi/) {
     my @fields = split />/, $line;
     $seen{$fields[1]}++;
     }
}

close IN;

foreach my $fields (sort { $seen{$b} <=> $seen{$a} } keys %seen)
{
 print "Hits: $seen{$fields}\n$fields\n";
}

prints
Hits: 1
>blahblah
Hits: 1
>blahblah

thanks for your help!
sm




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

Date: Mon, 04 Jun 2001 00:04:23 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: help with hashes
Message-Id: <4ujlht4m5n1ht3b77u11otjq3qjibskbij@4ax.com>

Steve Marshall wrote:

>prints
>Hits: 1
>>blahblah
>Hits: 1
>>blahblah

No it doesn't. It prints nothing. That is because the line

>     if ($line =~ /^>gi/) {

searches for a line starting with ">" followed by "gi". There is no such
line in your data.

If I drop the "gi", I get:

	Hits: 3
	blahblah

which could be useful to you, but somehow I doubt it. Your example data
is far from useful, it is not clear exactly what you're trying to
achieve. For starters, make not all lines the same if you actually want
to process different lines every time. Show us some realistic data.

>     if ($line =~ /^>gi/) {
>     my @fields = split />/, $line;
>     $seen{$fields[1]}++;
>    }
Boy that is ugly code. If all you want to do is strip of the ">", then
do:

	if($line =~ /^>(.*)/) {
	    $seen{$1}++;
	}

-- 
	Bart.


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

Date: 3 Jun 2001 16:38:23 -0700
From: weedmonster_99@yahoo.com (codeslayer)
Subject: Help with the $0 equivalent, portable for use in DOS/Windows/Win32-based environment.
Message-Id: <4b459565.0106031538.61b83584@posting.google.com>

Greetings:

I have a simple question:

I am not using UNIX, (though I usually do at work), and I need a
RELIABLE method for automatically grabbing the name of a PERL program
and telling the user what it is, in DOS or Windows. I have already
tried the following:

   print "The name of this file is $0 \n";

     and

   print "The name of this file is $ARGV[0] \n";

 ... both to no avail.

Any help would be truly appreciated.

Thanks.

--- P.S.:

What is the correct syntax to search for $0 in this forum?
everything I have tried will give me a 0 a best, but never the "$0"
combo
that I am looking for.

Thanks again.


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

Date: Sun, 03 Jun 2001 23:54:05 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Help with the $0 equivalent, portable for use in DOS/Windows/Win32-based environment.
Message-Id: <6ejlhtkdppbm5d9mn0mr7m5scp6sr65tc1@4ax.com>

codeslayer wrote:

>I am not using UNIX, (though I usually do at work), and I need a
>RELIABLE method for automatically grabbing the name of a PERL program
>and telling the user what it is, in DOS or Windows. I have already
>tried the following:
>
>   print "The name of this file is $0 \n";

What's wrong with $0? Do you nee the full path? The module FindBin has
already been suggested here before, although I didn't ever use it.

Or, do you want the perl executable? Look into the special variable $^X.

-- 
	Bart.


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

Date: Sun, 03 Jun 2001 19:53:40 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: mailing from perl
Message-Id: <3B1ACE04.4ED28129@earthlink.net>

Anonymous wrote:
> 
> I'm working on a script that looks essentially like so, but doesn't
> work:
> 
> open(FH,"mailing.list");
> 
> while(<FH>) {
>         system("mail $_  < a_file_to_mail");
> }
> 
> close FH;
> 
> any ideas?

Yes, don't invoke "mail" once per address, but have a single call to
"mail" which goes to all the addresses in the list...

chomp my @userlist = grep { !/^\s*#/ && /\S/ } do {
	open( my $fh, "mailing.list" ) or die "mailing.list: $!";
	<$fh>; }; # $fh closes when it goes out of scope
if( @userlist == 0 ) { die "No users!\n"; }
my $wait_gave = system("mail @userlist < a_file_to_mail");
if( $wait_gave == -1 ) {
	die "System call (mail) failed: $!";
} elsif( $wait_gave != 0 ) {
	my $exit_value = $? >> 8;
	my $signal_num = $? & 127;
	my $dumped_core = $? & 128;
	if( $dumped_core ) {
		die "Mail dumped core!";
	} elsif( $signal_num ) {
		use Config;
		my @names = split ' ', $Config{sig_name};
		my @nums  = split ' ', $Config{sig_num};
		my %names; @names{@nums} = @names;
		$signal_num = $names{$signal_num} or $signal_num;
		die "Mail aborted due to signal $signal_num";
	} elsif( $exit_value ) {
		die "Mail exited with return code $exit_value";
	} else {
		die "Shouldn't get here";
	}
} else {
	print "Mail sent ok\n";
}

*Any* time you call open, you should *always* check it's return value.
*Any* time you call system, you should *always* check it's return value.
If the call succeeded, system returns 0.  If not, handle it.  I handle
it be examining $? and printing an appropriate error message.  You could
handle it by simply saying something like
	die "system() failed: it returned $foo, and \$?==$?, \$!==$!";
but this kind of error message is rather cryptic looking and unhelpful.
Core dumps are usually bugs, of course, but the other things *can* be
understood.  If a program dies from a signal, it's because *something*
sent the signal to the program.  If a program exits with some return
value, you can look up in the manual page (use the "man" command from
the shell) to see what it means.

Another thing... you've probably got about a bazillion addresses in the
file mailing.list; perhaps you should use a special bulk mailer instead
of the "mail" program?

Oh, and instead of passing all those addresses on the commandline, you
should find a way to write the addresses to the mailer's stdin
instead... putting stuff from files onto the commandline is *so* unsafe.

For example:

{	my $sm;
	open( $sm, "|sendmail -t" ) or die "can't fork/exec $!";
	print $sm, "To: ex@amp.le";
	{	my $ml;
		open( $ml, "mailing.list" ) or die "mailing.list: $!";
		# no \n here, it's already included.
		print $sm, "Bcc: $_" while <$ml>;
		# $ml closes at end of scope
	}
	print $sm, "\n"; # end of mail headers
	{	my ($thefile, $buf, $bufsize);
		open( $thefile, "a_file_to_mail" )
			or die "a_file_to_mail;
		$bufsize = (stat($thefile))[11] or 1024;
		while( read( $thefile, $buf, $bufsize ) ) {
			print $sm, $buf;
		}
		# $thefile closes at end of scope
	}
	if( !close( $sm ) ) {
		# check $? here
	}
	# yes, $sm would close at end of scope, but since it's a pipe,
	# we *should* be checking the return value of close, and the
	# contents of $?, if the close failed.
}

-- 
The longer a man is wrong, the surer he is that he's right.


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

Date: Sun, 03 Jun 2001 19:16:11 +0500
From: Robert Sherman <rsherman@ce.gatech.edu>
Subject: Re: My multi upload script isnt working right...
Message-Id: <3B1A46AB.2247A18D@ce.gatech.edu>

following is a fully functional  upload script from the o'reilly cgi perl
book....perhaps you will find it useful (uses CGI.pm).


=======================================================
#!/usr/bin/perl -wT

use strict;
use CGI;
use Fcntl qw( :DEFAULT :flock );

use constant UPLOAD_DIR     => "/usr/local/apache/data/uploads";
use constant BUFFER_SIZE    => 16_384;
use constant MAX_FILE_SIZE  => 1_048_576;       # Limit each upload to 1 MB
use constant MAX_DIR_SIZE   => 100 * 1_048_576; # Limit total uploads to 100 MB

use constant MAX_OPEN_TRIES => 100;

$CGI::DISABLE_UPLOADS   = 0;
$CGI::POST_MAX          = MAX_FILE_SIZE;

my $q = new CGI;
$q->cgi_error and error( $q, "Error transferring file: " . $q->cgi_error );

my $file      = $q->param( "file" )     || error( $q, "No file received." );
my $filename  = $q->param( "filename" ) || error( $q, "No filename entered." );

my $fh        = $q->upload( "file" );
my $buffer    = "";

if ( dir_size( UPLOAD_DIR ) + $ENV{CONTENT_LENGTH} > MAX_DIR_SIZE ) {
    error( $q, "Upload directory is full." );
}

# Allow letters, digits, periods, underscores, dashes
# Convert anything else to an underscore
$filename =~ s/[^\w.-]/_/g;
if ( $filename =~ /^(\w[\w.-]*)/ ) {
    $filename = $1;
}
else {
    error( $q, "Invalid file name; files must start with a letter or number."
);
}

# Open output file, making sure the name is unique
until ( sysopen OUTPUT, UPLOAD_DIR . "/$filename", O_CREAT | O_RDWR | O_EXCL )
{
    $filename =~ s/(\d*)(\.\w+)$/($1||0) + 1 . $2/e;
    $1 >= MAX_OPEN_TRIES and error( $q, "Unable to save your file." );
}

# This is necessary for non-Unix systems; does nothing on Unix
binmode $fh;
binmode OUTPUT;

# Write contents to output file
while ( read( $fh, $buffer, BUFFER_SIZE ) ) {
    print OUTPUT $buffer;
}

close OUTPUT;

print $q->header( "text/plain" ), "File received.";

sub dir_size {
    my $dir = shift;
    my $dir_size = 0;

    # Loop through files and sum the sizes; doesn't descend down subdirs
    opendir DIR, $dir or die "Unable to open $dir: $!";
    while ( readdir DIR ) {
        $dir_size += -s "$dir/$_";
    }
    return $dir_size;
}


sub error {
    my( $q, $reason ) = @_;

    print $q->header( "text/html" ),
          $q->start_html( "Error" ),
          $q->h1( "Error" ),
          $q->p( "Your upload was not procesed because the following error ",
                 "occured: " ),
          $q->p( $q->i( $reason ) ),
          $q->end_html;
    exit;
}
====================================================




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

Date: Sun, 3 Jun 2001 20:34:13 -0400
From: David Coppit <newspost@coppit.org>
Subject: Re: Newbie trends over time
Message-Id: <Pine.SUN.4.33.0106032033280.1102-100000@mamba.cs.Virginia.EDU>

On Sat, 2 Jun 2001, Scott Howard wrote:

> 'Expert groups' are nice in theory, but in practice, that'd be the very
> first place newbies with poorly considered questions would go.

LOL! How about comp.lang.perl.useless-readers? .wrong-answers?
 .go-away? ;)

David



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

Date: 3 Jun 2001 17:39:54 -0700
From: krakle@visto.com (krakle)
Subject: Re: perl/cgi and dynamic hyperlink
Message-Id: <237aaff8.0106031639.3b1c069e@posting.google.com>

Godzilla burped:

"Forgive my terse wording but what is it with so many of
you using an expression "...something like" in your
articles? Do you want to contruct something like this
rule or construct this rule precisely as stated?"

I read a few of your previous postings and it seems like all you do is
nit pick at the way people post. Geesh you nit picked at my posting
because I provided the code I was having trouble on to be very
specific. Not everyone is going to use the words YOU want them to use,
and post how YOU want them to post.

By anychance are you a woman?


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

Date: Mon, 04 Jun 2001 00:47:47 GMT
From: echang@netstorm.net (E.Chang)
Subject: Re: perl/cgi and dynamic hyperlink
Message-Id: <Xns90B5D3F9430B5echangnetstormnet@207.106.93.86>

krakle@visto.com (krakle) wrote in
<237aaff8.0106031639.3b1c069e@posting.google.com>: 

> Godzilla burped:
> 
> "Forgive my terse wording but what is it with so many of
> you using an expression "...something like" in your
> articles? Do you want to contruct something like this
> rule or construct this rule precisely as stated?"
> 
> I read a few of your previous postings and it seems like all you do
> is nit pick at the way people post. Geesh you nit picked at my
> posting because I provided the code I was having trouble on to be
> very specific. Not everyone is going to use the words YOU want them
> to use, and post how YOU want them to post.

> By anychance are you a woman?

I do not agree with many of the statements in Godzilla!'s articles, and 
find some of her (yes, her) language rather coarse.  But *that* is  the 
most offensive line I have seen in my time on this newsgroup.

-- 
EBC


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

Date: 03 Jun 2001 18:33:08 -0500
From: Aaron Baugher <abaugher@esc.pike.il.us>
Subject: PlRPC causing trouble with STDIN/OUT
Message-Id: <haruchai.m3itidjg0b.fsf@esc.pike.il.us>

Hi,

I've just started using PlRPC (RPC::PlServer and
RPC::PlClient), and have run into a really strange problem.
I've got a CGI, that's pretty similar to the one in the man
pages, except that I made one server method so far.  The
client is pretty small, so I've copied it below. 

The problem comes when it attempts to run an external
program -- in this case, a PHP interpreter.  I write a bunch
of text (html with php commands) out to a file, and run php
on it, redirecting it to another file, and then read that
file back in and print it out.  (Obviously I'd normally do it
without so many steps and tmp files, but I'm trying to track
down the problem.)

It runs fine from the command line.  But when I hit it from
any browser, it displays the PHP headers, and then displays
my perl script!  When I check the tmp files, sure enough --
the one my script writes is fine, but the one the php
program outputs has my script in it, instead of my text.  

Any ideas what would cause this?  I'm assuming that between
apache, my CGI, PlClient, and the system call, something's
STDIN or STDOUT is getting clobbered by something else's,
and my script is getting fed to the php program instead of
the file I'm trying to feed it.  (Even though I've used 'php
-f'.)  Any idea what I can do to fix it?

Here's the whole script; the problem area is marked:

    #!/usr/bin/perl -w

    use strict;
    use CGI qw( header start_html );
    use RPC::PlClient;

    my $APP = "CPS";
    my $VER = 0.01;
    my $CR = "\n";

    my $text;
    for (qw( header.php index.html footer.html )){
      open IN, "tmpl/$_" or die $!;
      $text .= join '', <IN>;
      close IN;
    }

    eval {
      my $client = RPC::PlClient->new(
            'peeraddr' => 'localhost',
            'peerport' => 2050,
            'application' => 'CPS',
            'version' => 0.01,
            'logfile' => 1,
            );
      my %h = $client->Call('Hello', 'Hello', 'esc' );

      if( $h{OK} ){
        for (keys(%{$h{VARS}})){
          my $uc = uc($_);
          $text =~ s/\$$uc([^A-Z0-9])/$h{VARS}->{$_}$1/g;
        }

        open OUT, ">/tmp/cpcp.$$" or die $!;
        print OUT $text;
        close OUT;
        system( "/usr/local/bin/php -f /tmp/cpcp.$$ >/tmp/cpcp.out.$$");  

         ####   Here's the trouble
         ####   /tmp/cpcp.$$ gets the right text, but
         ####   /tmp/cpcp.out.$$ gets this script instead

        open IN, "/tmp/cpcp.out.$$" or die $!;  
        print join '', <IN>;               
        close IN or die $!;
      } else {
        print header;
        print "Error: $h{ERR}\n";
      }
    };
    if($@){
      print header;
      print "Error: $@";
    }


I also tried replacing the cumbersome file io above using
IPC::Open2, with:

  my( $in, $out ) = (FileHandle->new, FileHandle->new);
  my $pid = open2( $in, $out, "/usr/local/bin/php" );
  $out->print($text);
  $out->close;
  print join '', <$in>;

And I still get my CGI script back on the input filehandle,
just like above.



Thanks,
Aaron
-- 
abaugher@esc.pike.il.us - Coatsburg, IL, USA
Extreme Systems Consulting - http://esc.pike.il.us/
CGI, Perl, and Linux/Unix Administration


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

Date: Sun, 03 Jun 2001 20:36:38 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: readline  is strange on WinNT
Message-Id: <3B1AD816.461C2E63@earthlink.net>

Timeon de Marque wrote:
> 
> Probably 'cos I am new at this but
> and installation script I wrote asks for
> input and reads it using 'readline STDIN'
> 
> This works on Win95, Win98 but
> on WinNT4 it rattles through the script not
> stopping for breath at the readline.
> 
> What am I missing here?  Is there a subtle
> buffering difference in the two operating systems.
> 
> Works with $line = <STDIN> as an alternative,
> I just want to know that the NT problems is.

Was your perl compiled with cygwin?

-- 
The longer a man is wrong, the surer he is that he's right.


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

Date: Sun, 03 Jun 2001 18:55:03 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Recursing a directory tree
Message-Id: <3B1AC047.8DE10B38@earthlink.net>

Nan Wang wrote:
> 
> Arun Horne <a.b.horne@nospamexeter.ac.uk> wrote:
> > Does anyone have some simple code to recurse a directory tree please?? Best
> > regards Arun Horne.
> 
> Sure here's one, I did this a while ago without using Find:
> 
> sub traverse {
>         no strict 'refs';
>         my ($startdir,$i)=@_;
>         $i++;
>         my $FH="FH"."$i";
>         opendir ("$FH",$startdir) or die "blah";
>         my @allfiles=grep !/^\.\.?$/, readdir $FH;
>         closedir ($FH);
>         my $file='';
>         foreach $file (@allfiles) {
>                 chomp $file;
>                 my $file="$startdir/$file";
>                 if (-f $file) {
>                         # do whatever
>                 } elsif (-d $file) {
>                         &traverse ($dir,$i);
>                 }
>         }
> }

Umm, what's the point of the $i ?  Since it is closed almost right after
it is opened, does it matter at all if nested traverse() calls use the
same filehandle?  Also, is there anything wrong with just using a normal
glob/filehandle here, or better yet, something which will automatically
close when it goes out of scope?  And where does $dir come from?

sub traverse {
	my $startdir = $_[0];
	foreach my $file ( do {
		opendir( my $dh, $startdir ) or die $!;
		grep { !/^\.\.?$/ } readdir($dh); } ) {
		my $qualified = $startdir . "/" . $file;
		if( -f $qualified ) {
			# do whatever with $qualified and @_
		} elsif( -d _ && !-l _ ) {	# special _ filehandle
			local $_[0] = $qualified;
			&traverse;	# pass @_ to recursive call
		}
	}
}

Note: this code is untested.  Also, note that this piece of code should
allow you to pass extra arguments, which should get passed down through
the nested recurisve calls.

-- 
The longer a man is wrong, the surer he is that he's right.


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

Date: Mon, 4 Jun 2001 00:00:05 +0300
From: "Stuart Gall" <stuart@otenet.gr>
Subject: Re: using perl with msaccess
Message-Id: <9feegn$rk5$1@usenet.otenet.gr>

"Nicholas R. Markham" <nickmarkham@mailandnews.com> wrote in message
news:9fdnkn$lug$1@newsfeeds.rpi.edu...
> There's a module Win32::ODBC that I've used fairly successfully to run SQL
> queries on ODBC databases, which certainly include Access.  That might do
> what you want.
>

MSAccess only supports data retrieval via SQL. The only way to edit or
append is by using custom functions and DDE, which is messy because access
has to be running.
I don't know if this is possible with perl, I have done it using C.

Another alternative would be to port all the tables to a decent SQL package
and import them to access via ODBC. Then you could use SQL from perl read
write.

You mentioned ASP. It is much easier with asp. If you have the MS webserver.
I believe you can export MSAccess objects directly to the webserver as
asp's. You could probably do this without using the keyboard at all.

--

Stuart Gall
------------------------------------------------
This message is not provable.



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

Date: Sun, 03 Jun 2001 23:33:31 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: using perl with msaccess
Message-Id: <h9ilhtcbn4hch634h37vh9di00vem40tro@4ax.com>

Stuart Gall wrote:

>MSAccess only supports data retrieval via SQL.

>Another alternative would be to port all the tables to a decent SQL package
>and import them to access via ODBC. Then you could use SQL from perl read
>write.

Er... hello? I have DONE appending and updating to tables, with Access,
through DBI + DBD::ODBC. So I'm 100% sure it works.

>The only way to edit or
>append is by using custom functions and DDE, which is messy because access
>has to be running.
>I don't know if this is possible with perl, I have done it using C.

And there is also ADO, which works through OLE. The DBI mentions it, but
the demo code in the book doesn't work for me. Oh well.

-- 
	Bart.


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.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.

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 V10 Issue 1050
***************************************


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