[6443] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 67 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Mar 7 00:15:45 1997

Date: Thu, 6 Mar 97 21:00:28 -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           Thu, 6 Mar 1997     Volume: 8 Number: 67

Today's topics:
     Re: "Mod of read-only" on an open file <tchrist@mox.perl.com>
     Re: [h2ph] Can't convert .h files <tchrist@mox.perl.com>
     Re: ARGUMENTS - HELP <billc@tibinc.com>
     Re: Basic $ENV questions <tchrist@mox.perl.com>
     Re: Best way to return a hash from XSUB <tcl@caesun.msd.ray.com.CLIP.THIS.PART>
     Re: Best way to return a hash from XSUB <tcl@caesun.msd.ray.com.CLIP.THIS.PART>
     Re: Building variable variable names ?? <billc@tibinc.com>
     Re: can't find GDBM_File.pm <jeff@networkers.com>
     Re: Creating a Daemon <tchrist@mox.perl.com>
     Data Field Searching (Jason Eric Stajich)
     Re: delete some lines in a doc <tchrist@mox.perl.com>
     Re: Do I have to worry about memory leak if I am design <tchrist@mox.perl.com>
     examples of berkeley db use (Howard Cohen)
     Re: Exporter doesn't <roderick@argon.org>
     Re: File input through the web <tchrist@mox.perl.com>
     Help With Sockets <rruiz@cybercities.com>
     Re: How to create 666 file from www perl cgi? (Abigail)
     Re: How to use perl as an interface to another program <tchrist@mox.perl.com>
     Re: How to use perl as an interface to another program <tchrist@mox.perl.com>
     Re: i don't understand output from h2ph <roderick@argon.org>
     Re: keys() on a map() fails. Why? (Tim Gim Yee)
     newbie question: check if a number is in a list brz@hotmail.com
     Re: Newbie question: perl, OS/2, and #! <curtis@echomedia.com>
     Path problem. (Ian Mortimer)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 7 Mar 1997 03:17:02 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: "Mod of read-only" on an open file
Message-Id: <5fo1be$co6$4@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    Larry Prall <larry@lccinc.com> writes:
:use strict;
:foreach ( 'group', 'passwd', 'hosts' ) {
:    work( $_ );
:}
:
:sub work {
:    my $filename = '/etc/' . shift;
:    print qq(file is "$filename"\n);
:    open INPUT, $filename or die "Couldn't open $filename, ";
:    while (<INPUT>) {
:        print;
:    }
:}

Yup, that's expected behavior -- well, for me it is, once
I looked at it.  I don't imagine it was for you. :-)

The <INPUT> in the while tried to assign to $_.  $_ is currently
an alias to a constant string, which means you can't change it.
But you can't.  

This reminds me of variable suicide.  A lot.

The solution is to never use $_, or to always local()ize it.

Perhaps if the mythical 
    no implicit;
directive existed and worked (neither of which is true nor
planned) perhaps the compiler might have caught you.

--tom
-- 
	Tom Christiansen	tchrist@jhereg.perl.com
    "I will always write it the second way, so if you're optimizing for
    contrariness, it's obviously better to do it the second way."
    	--Larry Wall


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

Date: 7 Mar 1997 03:20:48 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: [h2ph] Can't convert .h files
Message-Id: <5fo1ig$co6$6@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    toheemin@iscs.nus.sg (Ee Ming) writes:
:I tried running h2ph script to convert C's .h files into perl's .ph files
:but I got a message that says that the files cannot be open, although the
:file exists. Anybody know what's wrong??

    1. become root
    2. cd /usr/include
    3. h2ph * sys/*

--tom
-- 
	Tom Christiansen	tchrist@jhereg.perl.com

    What about WRITING it first and rationalizing it afterwords?  :-)
                    --Larry Wall in <8162@jpl-devvax.JPL.NASA.GOV>


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

Date: Thu, 06 Mar 1997 22:22:11 -0500
From: Bill Cowan <billc@tibinc.com>
To: Coulon <X.Coulon@herts.ac.uk>
Subject: Re: ARGUMENTS - HELP
Message-Id: <331F89E3.2247@tibinc.com>

Coulon wrote:
> 
> Hello,
> I would like to write a Perl script what gets command line arguments,
> but I don't know how to do it. Is it stored in a variable/array ?
> Thanks for your help.
> Xavier Coulon
> X.Coulon@herts.ac.uk

Please see doc about @ARGV (special array) for command line arguments.

-- Bill
-----------------------------------------------------------------------
Bill Cowan <billc@tibinc.com>    Voice:919-490-0034   Fax:919-490-0143
Tiburon, Inc./3333 Durham-Chapel Hill Blvd Suite E-100/Durham, NC 27707


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

Date: 7 Mar 1997 03:25:51 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Basic $ENV questions
Message-Id: <5fo1rv$co6$8@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    ebabin@cyberenet.net (Eddie Babin) writes:
:: foreach $key (sort keys %ENV) {
::    print OUTFILE $ENV{$key},"\n";
:: }

:Thanks for your help.  This gave some of the environment variables.
:How can I access the rest?

There aren't any more.  I promise.

--tom
-- 
	Tom Christiansen	tchrist@jhereg.perl.com
"Espousing the eponymous /cgi-bin/perl.exe?FMH.pl execution model is like 
reading a suicide note -- three days too late."
	    --Tom Christiansen <tchrist@mox.perl.com>


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

Date: Thu, 06 Mar 1997 21:59:10 -0500
From: Tim Lewis <tcl@caesun.msd.ray.com.CLIP.THIS.PART>
Subject: Re: Best way to return a hash from XSUB
Message-Id: <331F847E.6A31@caesun.msd.ray.com.CLIP.THIS.PART>

Enrico Badella wrote:
> 
> 
> Which is the best way to return a hash from a XSUB? I tried creating a
> reference, blessing it then returning but id does not seem to work
> 
>         outAA = newRV(result);
>         sv_bless(outAA, gv_stashpv("ebrtest", FALSE));
>         EXTEND(sp, 1);
>     P   USHs(sv_2mortal(outAA));
> 
> What am I doing wrong?
> 

Well, I've never been able to get an answer about whether or not this is
the correct way to do this, but this is basically what I did:

void
YourFunc()
	PREINIT:
		char*	whatever;
	PPCODE:
                HV* HV_rtn;
                SV* HV_ref;

                SV* what;


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

Date: Thu, 06 Mar 1997 22:03:16 -0500
From: Tim Lewis <tcl@caesun.msd.ray.com.CLIP.THIS.PART>
Subject: Re: Best way to return a hash from XSUB
Message-Id: <331F8574.1AC3@caesun.msd.ray.com.CLIP.THIS.PART>

Enrico Badella wrote:
> 
> Which is the best way to return a hash from a XSUB? I tried creating a
> reference, blessing it then returning but id does not seem to work
> 
>         outAA = newRV(result);
>         sv_bless(outAA, gv_stashpv("ebrtest", FALSE));
>         EXTEND(sp, 1);
>     P   USHs(sv_2mortal(outAA));
> 
> What am I doing wrong?

Well, I've never been able to get an answer about whether or not this is
the correct way to do this, but this is basically what I did:

void
YourFunc()
	PREINIT:
		char*	whatever;
	PPCODE:
                HV* HV_rtn;
                SV* HV_ref;

                SV* what;

                HV_rtn = newHV();

                what = newSVpv(whatever, 0);

                hv_store(HV_rtn, "WHAT", 4, whatever, 0);

                # Create a reference to the hash
                HV_ref = sv_2mortal(newRV((SV *)HV_rtn));

                # Deincrement the reference count, because newRV 
                # increments the reference
                # count of the object, and eventually 
                # we want the object to go away.
                SvREFCNT_dec((SV *)HV_rtn);

                XPUSHs(HV_ref);

Let me know if you have any problems,
Tim


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

Date: Thu, 06 Mar 1997 23:15:30 -0500
From: Bill Cowan <billc@tibinc.com>
To: Wolfgang Reimann <reimann@merck.de>
Subject: Re: Building variable variable names ??
Message-Id: <331F9662.3A3B@tibinc.com>

Wolfgang Reimann wrote:
> 
> It's late in the evening and after staring at some lines of code and
> trying to find an easy solution. What i'm trying to do is quite simple
> for interpreted languages such as REXX and (must be) perl:
> 
> Building a variable name that contains a variable part, so that
> the result is a list of variables. In the following example i want to
> create variables $p1,$p2,$p3,$p4 and so on. I need these to fill a
> format. Do i have to use an array?
> 
> #!perl
>       @Privs = qw (SETPRV READALL BACKUP SHUTDOWN) ;
>           for ($n = 0; $n <= $#Privs ; $n++) {
>                $p$n   = $Privs[$n] ;
>               printf "%-10s %-10s\n","Variable ",$p$n
> 
> All i get running this is:
> 
> Scalar found where operator expected at var_of_var.pl line 4, near
> "$p$l"
>         (Missing operator before $l?)
> syntax error at var_of_var.pl line 4, near "$p$l   "
> Execution of var_of_var.pl aborted due to compilation errors.
> 
> (Perl 5.002_01    On  AlphaServer 2100     VMS 6.1)
> 
> Forgive me if that's too silly and i missed 10 FAQ's...
> 
> Wolfgang Reimann

What about?  Most of difference is the ${"p$n"}.

---------------- Revised Code ---------------------
@Privs = qw (SETPRV READALL BACKUP SHUTDOWN) ;
for ($n = 0; $n <= $#Privs ; $n++) {
        ${"p$n"}   = $Privs[$n] ;
}
printf "%-10s %-10s\n","Variable0 ", $p0;
printf "%-10s %-10s\n","Variable1 ", $p1;
printf "%-10s %-10s\n","Variable2 ", $p2;
printf "%-10s %-10s\n","Variable3 ", $p3;

--------- Output ---------------------
Variable0  SETPRV
Variable1  READALL
Variable2  BACKUP
Variable3  SHUTDOWN

-- Bill
-----------------------------------------------------------------------
Bill Cowan <billc@tibinc.com>    Voice:919-490-0034   Fax:919-490-0143
Tiburon, Inc./3333 Durham-Chapel Hill Blvd Suite E-100/Durham, NC 27707


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

Date: 06 Mar 1997 17:10:43 -0800
From: Jeff Coffin <jeff@networkers.com>
Subject: Re: can't find GDBM_File.pm
Message-Id: <m29140pkvg.fsf@networkers.com>

>>>>> "Broc" == Broc Seib <bseib@purdue.edu> writes:

Broc> I've got the GDBM distribution from MIT, built the libs, but lo,
Broc> there is not a GDBM_File.pm file!

Broc> Where do I find GDBM_File.pm?

It comes with the standard Perl5 distribution not the GDBM
distribution.  Try 'perl -MGDBM_File -e ;' from the command line to
see if it's in you @INC path (i.e. perl(5) is installed correctly).
If you get an error like:

finnegan:~ 17:07:48$ perl -MGDBM_Fil -e ;
Can't locate GDBM_Fil.pm in @INC.
BEGIN failed--compilation aborted.

It's not, and that's another issue...

Good Luck

-jeff




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

Date: 7 Mar 1997 03:19:31 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Creating a Daemon
Message-Id: <5fo1g3$co6$5@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    mattera@ssga.ssb.com (Luigi Mattera) writes:
:  I want to create a daemon process using perl, but the few books I
:have been able to find don't mention it at all.  Is there a way to do
:this?  I can create a daemon under C using system libraries and
:commands, but I don't know how to do this with perl.  Any suggestions?
:I have Perl V5, but my books are all based on V4.

Tell me what a daemon was, and we'll tell you how to make one.

:  Speaking of C system libraries, is there any way to recreate their
:use under perl?  I am interested in using some system calls under Perl
:and was wondering if they were useable or had to be implemented
:manually like fork.  If they exist under V5, then see my next
:paragraph.

syscall()  (man perlfunc)
XS  (man perlxstut)

:  Also, can anyone recommend a book on V5?  I only have access to V4
:books and I would like to read up on the differences between the two
:as we have v5 compiled.

The Camel, but I wrote (1/3 of) it, so I'm biased.  But it's still
what everyone else would recommend.  You'll see. 

--tom
-- 
	Tom Christiansen	tchrist@jhereg.perl.com
    : The ksh scripts do not have a problem with it. 
    That's because ksh doesn't much mind opening up security holes.  The
    absence of taint checks is not exactly a feature.


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

Date: 7 Mar 1997 03:47:45 GMT
From: jes12@acpub.duke.edu (Jason Eric Stajich)
Subject: Data Field Searching
Message-Id: <5fo351$ari@newsgate.duke.edu>

Hi I have a simple little question to Perl users.
I have a BIG db file, which store some various genetic information.  I need 
to extract only particular fields so to create a new db file that contains 
only information for a particular chromosone. 
[see below first]  

The fields are separated by a blank line.  
What I need is every field which begins with Pool.  
But then I also need every PAC contained in the 'Pool' fields 
(they are unique names in the quotes for what I can tell) 
along with the information stored about the PAC (which is stored in the 
same format as the 'Pool').  
If it was just the pools I needed I would have just awk-ed it out by 
blank line where the first 
line was \Pool : "pool_\ however now I am not sure if 
I should dump out the pool's first to a file, then reread this file and 
look at PAC's and find those in the original file to dump out. Or I could 
try and do it all at one time (reading in the pool, then find the first PAC 
write it out, return to second PAC, when done write out Pool).  
The first idea really would work better since I would most likely want to 
write all the pool's first then all the PAC's (order doesn't matter), an
want to cut down on the number of searches I am doing.  

If I just wanted to dump all the pool fields out first to a file, then read 
the file back in, taking each PAC line and using it as search argument for
the original file, how would I go about it?   Not knowing Perl, I wanted to 
know if anyone thought it would be the best choice of techniques (before I 
spend the time learning it), or I could just hack a little c program that 
would handle it.  Reusability is probably not the key here...

[example db fragment, names changed to protect the innocent :]
Pool : "pool_H1"
Positive_PAC     "dXXXXXX" "dYYY"
Positive_PAC     "dXXXXXX" "dYYY"
Positive_PAC     "dXXXXXX" "dYYY"
Positive_PAC     "dXXXXXX" "dYYY"
 ...[and so forth]...

Pool: "pool_H3"
Positive_PAC     "dXXXXXX" "dYYY"
Positive_PAC     "dXXXXXX" "dYYY"
Positive_PAC     "dXXXXXX" "dYYY"
 ...

PAC: "dXXXXXX"
 ...
 ...
etc.



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

Date: 7 Mar 1997 03:38:48 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: delete some lines in a doc
Message-Id: <5fo2k8$co6$12@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    LMD/T/KR <lmdtlb@lmd.ericsson.se> writes:
:To all the PERL experts, 

Most have fled.

:I am new in the PERL lang. But I have to 
:make a little script to remove some lines in a document. I have reach
:the point where I can open the file and and print the lines I would like 
:to delete. 
:1. have do I delete the line(s) ?
:2. have do make/save the new file ? ( could it be the same file ? )

You do what every editor does: you write your changes to a new copy and
a new file, possibly renaming the new one to the old one when you're done.

Or see the -i flag in the perlrun man page.

I answer this question every day on this newsgroup, or so it seems.

--tom
-- 
	Tom Christiansen	tchrist@jhereg.perl.com
"In general, it is best to assume that the network is filled with malevolent
entities that will send in packets designed to have the worst possible effect"
--the draft "Requirements for Internet Hosts" RFC


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

Date: 7 Mar 1997 03:23:07 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Do I have to worry about memory leak if I am designing a perl deamon?
Message-Id: <5fo1mr$co6$7@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    Eryq <eryq@enteract.com> writes:
:(Anyone... are we ever going to get mark-and-sweep?  Just curious.)

Larry says:

    M.J.T. Guy writes:
    : Daniel Mahler <dmahler@ozemail.com.au> posted to c.l.p.m
    : > I have been thinking about getting sound garbage collection
    : > in Perl by simply building it with the Bohm-Demers garbage collector
    : > installed in the C compiler
    : 
    : Would this break the invariance of the stringified form of references?

    Stringified (or numified) references are never reference counted,
    which is why Perl prohibits you from turning them back into real
    references.  So I think the answer is that it wouldn't break it.

    However, I think what Perl really wants is a voluntary garbage
    collector.  That is, one that you could invoke explicitly when
    you're at the top of the loop and don't have anything better to do.
    (Or when you're running out of memory and are desperate.)  I don't
    think you want to do without reference counting in the general case,
    because by and large people want their destructors run when they
    exit the scope in question, and not at some random time after that.
    For a special experimental version of Perl, it might be okay to
    have an implementation with uncounted references, but I wouldn't
    want to inflict that on everyone by default.  I think a voluntary
    garbage collector would satisfy people who just want to guarantee
    that their daemon doesn't grow forever because of reference loop bugs.

    My general attitude towards garbage collectors is that people ought
    to pick up after themselves and not expect their mother to do it.
    On the other hand, I do have a maid come in and clean periodically.
    But I like to think it's voluntary...

    Larry

--tom
-- 
	Tom Christiansen	tchrist@jhereg.perl.com

    In general, they do what you want, unless you want consistency.
            --Larry Wall in the perl man page


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

Date: 7 Mar 1997 00:57:33 GMT
From: rlogin@best.com (Howard Cohen)
Subject: examples of berkeley db use
Message-Id: <5fnp5t$p8k$1@nntp2.ba.best.com>
Keywords: DB_File, BerkeleyDB

Hi. After much on-line research I am leaning towards using the Berkeley
Database via perl's tie facility.  Before I dive in I'd love to review
some examples of its use.  I am already familiar with perl (although I'm
still learning perl5).  I tried to find examples but I'm having no
luck -- there is so much to look through out there...  

I have the Nutshell Perl5 book, but the coverage is brief even though 
there are some trivial examples (and one non-trivial example on locking).

Can anyone point me to an archive of examples which might include
use of the Berkeley db?  Are any of you using the berkeley db and if
so would you advise me against it?  My second choice is gdbm.

Heck, I'd be interested in seeing examples of any of the different
*db*-style databases perl understands.  I know they are out there 
somewhere...

If it makes any difference, I intend to use the database from a cgi
tool. Like, I'm sure nobody has ever done *that* before... ;-)

Any useful pointers would be appreciated.

Thanks for your consideration,

	Howard Cohen
	hoco@timefold.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
                 /\                 T I M E F O L D (tm)
           _____/  \          Software Configuration Management
          / \  /    \          Training & Consulting Services
         /   \/______\
        /           \                hoco@timefold.com
       / Timefold(tm)\             http://www.timefold.com
      /_______________\               (510) 521-0124


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

Date: 6 Mar 1997 19:41:07 -0500
From: Roderick Schertler <roderick@argon.org>
To: cos@zax.whoville.leftbank.com (Ofer Inbar)
Subject: Re: Exporter doesn't
Message-Id: <pzhgiolep9.fsf@eeyore.ibcinc.com>

On 5 Mar 1997 00:22:04 -0500, cos@zax.whoville.leftbank.com (Ofer Inbar) said:
> 
> So, what happened to the goodvalue of $variable in package main?

If you'd use the -w switch you'd be home by now.

    $ perl -w t
    Unquoted string "variable" may clash with future reserved word at MyModule.pm line 5.
    Unquoted string "variable" may clash with future reserved word at MyModule.pm line 6.
    module: goodvalue
    Name "main::MyModule" used only once: possible typo at t line 4.
    Use of uninitialized value at t line 3.
    script: 
    Use of uninitialized value at t line 4.
    script qualified: :variable

The main problem is in this line:

    @EXPORT = (variable);

A type-less name in an @EXPORT list indicates a subroutine.  Also,
you're using a lower-case alphabetic bearword, that's almost always a
mistake.  You wanted

    @EXPORT = qw($variable);

(note qw() in addition to $, see perlop(1)).

Also, the script you posted said

    print "script qualified: $MyModule:variable\n";

but that's wrong, you need two colons between MyModule and variable.

-- 
Roderick Schertler
roderick@argon.org


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

Date: 7 Mar 1997 03:40:29 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: File input through the web
Message-Id: <5fo2nd$co6$13@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    rad91@best.com (Ronnie Diaz) writes:
:Is it possible to to write files in perl scripts called by a web page?
:I have the following, and its not working (though it works fine on the
:shell).

:STDOUT will get printed in HTML, but not on a file 'submitted_file'.
:Am I going about this wrong?

Yup.  You didn't read 

    http://www.perl.com/perl/faq/idiots-guide.html

--tom
-- 
	Tom Christiansen	tchrist@jhereg.perl.com

"Lisp has all the visual appeal of oatmeal with fingernail clippings mixed in."
	--Larry Wall in <1994Jul21.173737.16853@netlabs.com>


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

Date: 7 Mar 1997 00:46:50 GMT
From: "Rudy Ruiz" <rruiz@cybercities.com>
Subject: Help With Sockets
Message-Id: <01bc2a92$620ad480$53b08ccc@mystra>


	Can anyone point me to some definitive and thorough resources regarding
Perl and Sockets? I want to learn it, not rip someones code. (That will
happen after I know what I'm doing.)
	Thanks.

		Rudy


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

Date: Fri, 7 Mar 1997 02:14:15 GMT
From: abigail@ny.fnx.com (Abigail)
Subject: Re: How to create 666 file from www perl cgi?
Message-Id: <E6nI7s.4n2@nonexistent.com>

On Thu, 6 Mar 1997 09:52:07 +0000, Charlie Stross wrote in comp.lang.perl.misc:
++ <BLINK>Don't read news via web browser<FONT FACE="WingDings"><FONT
++ SIZE="+3">
++ 
++ Geoffrey Hebert<soccer@microserve.net> wrote (in article
++ <5fidsl$1p8$1@news3.microserve.net>):
++ >I want to create a file with a perl cgi script that is initiated from
++ >the web.
++ >
++ >If I create the file as the owner with 666 permissions from my telnet
++ >account, everything works fine.  I can then open with ">filename"
++ >
++ >Open works only if I created the file!  I want the cgi to create the
++ >file.  Seems as though security is stopping me.
++ 
++ Very probably.
++ 
++ Assuming you're running on a UNIX system ...
++ 
++ CGI scripts are frequently executed by the web server with a UID of
++ 'nobody',
++ specifically as a security precaution against scripts written by people
++ who haven't read the WWW security FAQ. Thus, you can't create a file in 
++ a directory unless the directory itself is world-executable and world-
++ writable. (You can confirm this, if you're running Apache or NCSA httpd,
++ by looking in the httpd.conf file of your server. If it's not mentioned,
++ it may well default to whatever's compiled in ...)
++ 
++ Solutions:
++ 
++ a) make the directory your CGI script wants to create files in
++ world-writable,
++ or
++ b) make your CGI script set-UID root. (Deprecated.)

Or c) Create a UID 'www', and let it own the directory it needs to
      write to.


c) is my preferred option, but let's not talk too much CGI here.



Abigail



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

Date: 7 Mar 1997 03:10:56 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: How to use perl as an interface to another program
Message-Id: <5fo100$co6$3@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    jiangj@bnr.ca (John Jiang) writes:
:Greetings,
:
:	I am trying to use the open() which has a pipe symbol (|) in
:the filename  to open a command. If I put pipe at the beginning I can
:write and if I put pipe at the end of filename then I can read. My
:question is : How can I open a command and do input/output at the same
:time like interactively. Thanks

For Larry's sake, this is even in the very man page.  How could
you miss it?


=item open FILEHANDLE,EXPR

=item open FILEHANDLE

Opens the file whose filename is given by EXPR, and associates it with
FILEHANDLE.  If FILEHANDLE is an expression, its value is used as the
name of the real filehandle wanted.  If EXPR is omitted, the scalar
variable of the same name as the FILEHANDLE contains the filename.
(Note that lexical variables--those declared with C<my>--will not work
for this purpose; so if you're using C<my>, specify EXPR in your call
to open.)

If the filename begins with '<' or nothing, the file is opened for input.
If the filename begins with '>', the file is truncated and opened for
output.  If the filename begins with '>>', the file is opened for
appending.  You can put a '+' in front of the '>' or '<' to indicate that
you want both read and write access to the file; thus '+<' is almost
always preferred for read/write updates--the '+>' mode would clobber the
file first.  The prefix and the filename may be separated with spaces.
These various prefixes correspond to the fopen(3) modes of 'r', 'r+', 'w',
'w+', 'a', and 'a+'.

If the filename begins with "|", the filename is interpreted as a command
to which output is to be piped, and if the filename ends with a "|", the
filename is interpreted See L<perlipc/"Using open() for IPC"> for more
examples of this.  as command which pipes input to us.  (You may not have
a raw open() to a command that pipes both in I<and> out, but see
L<IPC::Open2>, L<IPC::Open3>, and L<perlipc/"Bidirectional Communication">
for alternatives.)

Opening '-' opens STDIN and opening 'E<gt>-' opens STDOUT.  Open returns
non-zero upon success, the undefined value otherwise.  If the open
involved a pipe, the return value happens to be the pid of the
subprocess.  

If you're unfortunate enough to be running Perl on a system that
distinguishes between text files and binary files (modern operating
systems don't care), then you should check out L</binmode> for tips for
dealing with this.  The key distinction between systems that need binmode
and those that don't is their text file formats.  Systems like Unix and
Plan9 that delimit lines with a single character, and that encode that
character in C as '\n', do not need C<binmode>.  The rest need it.

Examples:

    $ARTICLE = 100;
    open ARTICLE or die "Can't find article $ARTICLE: $!\n";
    while (<ARTICLE>) {...

    open(LOG, '>>/usr/spool/news/twitlog'); # (log is reserved)

    open(DBASE, '+<dbase.mine');	    # open for update

    open(ARTICLE, "caesar <$article |");    # decrypt article

    open(EXTRACT, "|sort >/tmp/Tmp$$");     # $$ is our process id

    # process argument list of files along with any includes

    foreach $file (@ARGV) {
	process($file, 'fh00');
    }

    sub process {
	local($filename, $input) = @_;
	$input++;		# this is a string increment
	unless (open($input, $filename)) {
	    print STDERR "Can't open $filename: $!\n";
	    return;
	}

	while (<$input>) {		# note use of indirection
	    if (/^#include "(.*)"/) {
		process($1, $input);
		next;
	    }
	    ...		# whatever
	}
    }

You may also, in the Bourne shell tradition, specify an EXPR beginning
with "E<gt>&", in which case the rest of the string is interpreted as the
name of a filehandle (or file descriptor, if numeric) which is to be
duped and opened.  You may use & after E<gt>, E<gt>E<gt>, E<lt>, +E<gt>,
+E<gt>E<gt>, and +E<lt>.  The
mode you specify should match the mode of the original filehandle.
(Duping a filehandle does not take into account any existing contents of
stdio buffers.)
Here is a script that saves, redirects, and restores STDOUT and
STDERR:

    #!/usr/bin/perl
    open(SAVEOUT, ">&STDOUT");
    open(SAVEERR, ">&STDERR");

    open(STDOUT, ">foo.out") || die "Can't redirect stdout";
    open(STDERR, ">&STDOUT") || die "Can't dup stdout";

    select(STDERR); $| = 1;	# make unbuffered
    select(STDOUT); $| = 1;	# make unbuffered

    print STDOUT "stdout 1\n";	# this works for
    print STDERR "stderr 1\n"; 	# subprocesses too

    close(STDOUT);
    close(STDERR);

    open(STDOUT, ">&SAVEOUT");
    open(STDERR, ">&SAVEERR");

    print STDOUT "stdout 2\n";
    print STDERR "stderr 2\n";


If you specify "E<lt>&=N", where N is a number, then Perl will do an
equivalent of C's fdopen() of that file descriptor; this is more
parsimonious of file descriptors.  For example:

    open(FILEHANDLE, "<&=$fd")

If you open a pipe on the command "-", i.e., either "|-" or "-|", then
there is an implicit fork done, and the return value of open is the pid
of the child within the parent process, and 0 within the child
process.  (Use C<defined($pid)> to determine whether the open was successful.)
The filehandle behaves normally for the parent, but i/o to that
filehandle is piped from/to the STDOUT/STDIN of the child process.
In the child process the filehandle isn't opened--i/o happens from/to
the new STDOUT or STDIN.  Typically this is used like the normal
piped open when you want to exercise more control over just how the
pipe command gets executed, such as when you are running setuid, and
don't want to have to scan shell commands for metacharacters.  
The following pairs are more or less equivalent:

    open(FOO, "|tr '[a-z]' '[A-Z]'");
    open(FOO, "|-") || exec 'tr', '[a-z]', '[A-Z]';

    open(FOO, "cat -n '$file'|");
    open(FOO, "-|") || exec 'cat', '-n', $file;

See L<perlipc/"Safe Pipe Opens"> for more examples of this.

Explicitly closing any piped filehandle causes the parent process to
wait for the child to finish, and returns the status value in C<$?>.
Note: on any operation which may do a fork, unflushed buffers remain
unflushed in both processes, which means you may need to set C<$|> to
avoid duplicate output.

Using the constructor from the IO::Handle package (or one of its
subclasses, such as IO::File or IO::Socket),
you can generate anonymous filehandles which have the scope of whatever
variables hold references to them, and automatically close whenever
and however you leave that scope:

    use IO::File;
    ...
    sub read_myfile_munged {
	my $ALL = shift;
	my $handle = new IO::File;
	open($handle, "myfile") or die "myfile: $!";
	$first = <$handle>
	    or return ();     # Automatically closed here.
	mung $first or die "mung failed";	# Or here.
	return $first, <$handle> if $ALL;	# Or here.
	$first;					# Or here.
    }

The filename that is passed to open will have leading and trailing
whitespace deleted.  To open a file with arbitrary weird
characters in it, it's necessary to protect any leading and trailing
whitespace thusly:

    $file =~ s#^(\s)#./$1#;
    open(FOO, "< $file\0");

If you want a "real" C open() (see L<open(2)> on your system), then
you should use the sysopen() function.  This is another way to
protect your filenames from interpretation.  For example:

    use IO::Handle;
    sysopen(HANDLE, $path, O_RDWR|O_CREAT|O_EXCL, 0700)
	or die "sysopen $path: $!";
    HANDLE->autoflush(1);
    HANDLE->print("stuff $$\n");
    seek(HANDLE, 0, 0);
    print "File contains: ", <HANDLE>;

See L</seek()> for some details about mixing reading and writing.
-- 
	Tom Christiansen	tchrist@jhereg.perl.com
"Espousing the eponymous /cgi-bin/perl.exe?FMH.pl execution model is like 
reading a suicide note -- three days too late."
	    --Tom Christiansen <tchrist@mox.perl.com>


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

Date: 7 Mar 1997 03:08:56 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: How to use perl as an interface to another program
Message-Id: <5fo0s8$co6$2@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    jiangj@bnr.ca (John Jiang) writes:
:	I am trying to use the open() which has a pipe symbol (|) in
:the filename  to open a command. If I put pipe at the beginning I can
:write and if I put pipe at the end of filename then I can read. My
:question is : How can I open a command and do input/output at the same
:time like interactively. Thanks

All questions are FAQs.

=head2 How can I open a pipe both to and from a command?

The IPC::Open2 module (part of the standard perl distribution) is an
easy-to-use apporach that internally uses pipe(), fork(), and exec()
to do the job.  Make sure you read the deadlock warnings in its
documentation, though (see L<IPC::Open2>).

--tom
-- 
	Tom Christiansen	tchrist@jhereg.perl.com


    "This sentence no verve." --Larry Wall


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

Date: 6 Mar 1997 19:11:20 -0500
From: Roderick Schertler <roderick@argon.org>
To: David Winter <winter@nevis1.nevis.columbia.edu>
Subject: Re: i don't understand output from h2ph
Message-Id: <pzk9nklfzi.fsf@eeyore.ibcinc.com>

On Wed, 05 Mar 1997 23:19:14 -0500, David Winter <winter@nevis1.nevis.columbia.edu> said:
> 
> [h2ph generated code:]
> 
>             eval " &memset(( &void *)($p), 0, $sizeof{*($p}))";
[...]
>             eval " &bzero(($p), $sizeof{*($p}))";
[...]
> 
> namely, what is going on with the "( &void *)" piece?  and what about the
> "$sizeof{*($p}))" part?

Nothing useful.  This is fixed in the h2ph which will ship with 5.004.
Until then you could just tweak the output yourself (just delete these
routines as no Perl code will use &FD_ZERO) or grab h2ph out of the
developer version.

-- 
Roderick Schertler
roderick@argon.org


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

Date: Thu, 06 Mar 1997 17:19:01 GMT
From: tgy@chocobo.org (Tim Gim Yee)
Subject: Re: keys() on a map() fails. Why?
Message-Id: <331ecad6.102676460@news.oz.net>

On 6 Mar 1997 19:55:06 GMT, nik@coconut.blueberry.co.uk (Nik Clayton)
wrote:

>How do,

'po! (and hi!)

>I'm trying to use the map() func to build an assoc. array, and then use the
>keys() function to get the keys from this array.
>
>This works fine if I use a temporary variable to hold the hash, but not
>if I try and use keys() directly on the output of map().
>
>Why?
>
>This is with
>
>    This is perl, version 5.003 with EMBED
>        built under freebsd at Nov 13 1996 17:22:42
>        + suidperl security patch
>
>This code fragment works
>
>    #!/usr/local/bin/perl
>    %foo = map { $_ => 1 } ( 1, 2, 3);	# Build assoc. array
>    print join(':', keys %foo);
>
>And prints '1:2:3' as expected.
>
>This one
>
>    #!/usr/local/bin/perl
>    print join(':', keys map { $_ => 1 } ( 1, 2, 3 ) );
>
>fails. The error message is
>
>    Type of arg 1 to keys must be hash (not map iterator)
>
>As I say, why?

map {$_=>1} (1,2,3) returns a list that looks like (1,1,2,1,3,1).
%foo is more than happy to slurp this up.  'keys map' fails because
'keys' is expecting a hash for its argument not a list...

So give it an anonymoush hash, like so:
    print join (':', keys %{{map {$_=>1} (1..10)}});
                          ^^^                   ^^

>FWIW, I'm trying to shrink down the following one liner,
>
>    /usr/local/bin/perl -e \
>        'chomp($_=<>);%_=map{$_=>1}split(/:/);print join(":",keys %_);'
>
>(which, for those that are interested, takes a ':' delimited string, say,
>$PATH, and returns the same string with duplicate elements removed).

This works:
    perl -e "chomp($_=<>);print join':',keys %{{map{$_=>1}split/:/}};"

As does this:
    perl -e "chomp($_=<>);print join':',grep{!$_{$_}++}split/:/;"

Or with switches:
    perl -aF: -lpe "$_=join':',grep{!$_{$_}++}@F"

The switches are explained nicely in Randal's first UnixReview column
at http://w3.stonehenge.com/merlyn/UnixReview/

HTH...


--
Tim Gim Yee             tgy@chocobo.org
http://www.chocobo.org/~tgy/moogle.html
'po!


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

Date: Thu, 06 Mar 1997 19:32:04 -0600
From: brz@hotmail.com
Subject: newbie question: check if a number is in a list
Message-Id: <857697754.14203@dejanews.com>



Say I have a list of numbers {1, 2 ,4, 6, 9}
and I want to check if $a is in this list...
how do i do it?

thanks!

brz

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


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

Date: 7 Mar 1997 03:53:00 GMT
From: "Curtis Maurand" <curtis@echomedia.com>
Subject: Re: Newbie question: perl, OS/2, and #!
Message-Id: <01bc2aaa$e2d5ca80$334311cc@curtis>



Joel Earl <earl@shadowfax.rchland.ibm.com> wrote in article
<EARL.97Mar5135132@shadowfax.rchland.ibm.com>...
> In article <3317C460.23F5@trader.com> Webmaster <NPHS@trader.com> writes:
> 
> > Thanks to a "proprietary hardware" stipulation in an Internet
connection 
> > grant my school received, we now have an OS/2 server that I am 
> > attempting to run perl on. 

  Nothing wrong with that.  Its 30% faster than NT



> 
> extproc perl -x -S

Should the file actually start with /*  */ to say that its REXX or just a 
batch file?





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

Date: 7 Mar 1997 02:34:06 GMT
From: mortimer@physics.uq.oz.au (Ian Mortimer)
Subject: Path problem.
Message-Id: <5fnuqu$k1m$1@nargun.cc.uq.edu.au>

Perl 5.003 is installed on our server under /usr/local.  On some
of our clients this is mounted under /usr/local/tools.  

I'm using this simple test program on the client:

   #!/usr/local/tools/bin/perl
   dbmopen(%verb, "TMP_verb",0755);

It fails with this message:

   No dbm on this machine at tst line 2.

So I did:

   export PERL5LIB=/usr/local/tools/lib/perl5

and now it fails with:

   AnyDBM_File doesn't define a TIEHASH method at tst line 2

Does anyone what know what else I need to set to get this to work?
Any help greatly appreciated.

Thanks
Ian


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

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 67
************************************

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