[7325] in Perl-Users-Digest
Perl-Users Digest, Issue: 950 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Aug 30 01:07:20 1997
Date: Fri, 29 Aug 97 22:00:28 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 29 Aug 1997 Volume: 8 Number: 950
Today's topics:
Re: <> operator memory leak? (Ken Williams)
>>> COMPUTER SOFTWARE / HARDWARE <<< "DISCOUNTS !" software@discount-software10.com
Re: build problem <rra@stanford.edu>
Re: Bus Error in ora_login <rra@stanford.edu>
changing dir of parent shell <godzilla@futuris.net>
Re: Compiling perl5.004.01 on solaris 2.5.1 (David Combs)
Re: Help - Displaying text files!!! (Tad McClellan)
Re: how to set shell variable from perl? (Charles DeRykus)
Re: indexed Search Engine <rsmith@tingley.net>
Invalid Transmission error <bhaisten@bellsouth.net>
Re: ipc socket as 0_NONBLOCK <rra@stanford.edu>
Re: module problems <rra@stanford.edu>
Re: New to the business! <rootbeer@teleport.com>
Re: Out of memory problem <rootbeer@teleport.com>
Re: Perl & Shadow Passwords authentitacion. (Michael W Peterson)
Re: Perl & Shadow Passwords authentitacion. <rootbeer@teleport.com>
Perl for DOS: How do I reference long filenames? peterarm@r2tech.com
Perl Pipes and FileHandles <mcgrattm@cts.com>
PERL,file locking, vipw & Solaris2.5.1 twod@not.valid
perldoc (Kevin)
Re: rsh a Perl script <rra@stanford.edu>
Re: rsh a Perl script <rootbeer@teleport.com>
Re: rsh a Perl script <doug@ono.tc.net>
Script to change passwd... questions on how (Andrew Kerr)
Re: Setting the TZ time variable within Perl <ninofior@adel.tafe.sa.edu.au>
Simple Question on grep <devonc@inetnebr.com>
Re: Simple Question on grep <rootbeer@teleport.com>
Re: sockets on IRIX? <scotth@sgi.com>
split() on an empty string (Ken Williams)
Re: struct in perl (dave)
Re: struct in perl <rootbeer@teleport.com>
Re: When to use "use strict" (Ken Williams)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 29 Aug 1997 20:02:19 -0400
From: ken@forum.swarthmore.edu (Ken Williams)
Subject: Re: <> operator memory leak?
Message-Id: <ken-2908972002190001@news.swarthmore.edu>
Here's one recommendation. Don't read the whole directory into memory at once:
for (;;) {
opendir DIR,$ROOT;
my $file;
while ($file = readdir DIR) {
open (FIL,$ROOT.$file);
while (<FIL>) {
}
close FIL;
}
closedir DIR;
}
=====================================
I don't know how this memory might be interacting with the memory that
gets stuck in $_ when you read <FIL>, but I suppose it might be causing a
problem. I don't know too much about the internal memory structure of
Perl.
Good luck.
In article <5tv74i$7g9@alvis.diku.dk>, joshu@diku.dk (Gargle Zndflxtzyh) wrote:
>I'm trying to write a program that's supposed to run
>for hours on end, but it globs up too much memory, and
>to begin with I thought it was a memory leak in
>my database-driver which is fairly beta, so I decided
>to do a wrapper that restarts the program every hour.
>
>But then another program that didnt use the database
>exhibited the same problem...And after staring at my
>code for hours to find circular references or hashes
>that aren't deleted properly and so forth I've found
>that this short code snippet can use up all my RAM
>in quite a short while
>(and Im working on an SGI IRIX machine with 128 megs of RAM):
>
>=====================================
>#!/usr/bin/perl
>
>$ROOT = "/usr/local/data/";
>
>for (;;) {
> opendir DIR,$ROOT;
> for (readdir DIR) {
> open (FIL,$ROOT.$_);
> while (<FIL>) {
> }
> close FIL;
> }
> closedir DIR;
>}
>=====================================
>
>/usr/local/data on my machine is a directory containing about 20.000
>files...So I can understand if the array from readdir DIR might
>get a little big, but if I comment out the 4 lines inside
>the innermost for-loop, the problem goes away (the process grows to about
>4 megs and stays there).
>
>And none of the files are bigger than about 100k (they're html-files).
>
>So now I begin thinking, perhaps there's something wrong with my
>perl binary...perhaps it wasn't compiled properly, but I find
>the same problems on a Pentium Linux (But both perl-bins were
>compiled by the same person). (I've also reproduced the error on
>a HP-UX version 10).
>
>The thing is, though, that if I use another directory containing
>less files, It doesn't grow so violently, and when the ending
>brace of the outermost for-loop is reached, the size shrinks again.
>
>So it's not a complete bug. But can anyone tell me why I have
>these problems?
>
>Is there some kind of buffer thing that I don't know about, or
>some cache...or is it something very simple that I've overlooked?
>
>btw. This version of the program works fine (ie. doesn't grow in size):
>
>======================================
>#!/usr/bin/perl -w
>$ROOT = "/usr/local/data/";
>
>for (;;) {
>opendir DIR,$ROOT;
>for (readdir DIR) {
> print "opening $_\n";
> open (FIL,$ROOT.$_) or die $!;
># while (<FIL>) {
># }
> $txt = `cat $ROOT$_`;
> close FIL;
>}
>}
>=====================================================
>
>
>Please help me, any response will be accepted gladly.
>
>
>thank you.
>--
>"Writing for a penny a word is ridiculous. If a man really wants
>to make a million dollars, the best way would be to start his own
>religion." Science Fiction writer L. Ron Hubbard.
>====================== Anders Nielsen, joshu@diku.dk =========================
-Ken Williams
The Math Forum
ken@forum.swarthmore.edu
------------------------------
Date: Sat, 30 Aug 1997 00:26:52 -0700
From: "DISCOUNTS !" software@discount-software10.com
Subject: >>> COMPUTER SOFTWARE / HARDWARE <<<
Message-Id: <300897002652@discount-software10.com>
<<<<<<< COMPUTER SOFTWARE / HARDWARE >>>>>>>
>>> UP TO 90 % OFF <<<
http://www.quantcom.com/auctionfirst/
<<==><=>=<<=>>>>===<
------------------------------
Date: 29 Aug 1997 16:38:14 -0700
From: Russ Allbery <rra@stanford.edu>
To: "Anthony R. Whyte" <taurus@frontiernet.net>
Subject: Re: build problem
Message-Id: <m3203czhjt.fsf@windlord.Stanford.EDU>
[ Posted and mailed. ]
Anthony R Whyte <taurus@frontiernet.net> writes:
> Trying to build the latest stuff on my linux/slackware system but keep
> dying around use of -ldl. There is a libdl.so.1.7.14* in my /lib
> directory.
Common problem with some Linux distributions. Solution is to make another
symlink for the shared library:
cd /lib
ln -s libdl.so.1.7.14 libdl.so
The general way this works is that ld looks for libdl.so when linking and
ld.so looks for libdl.so.1 when running the program, so you need them
both.
--
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print
------------------------------
Date: 29 Aug 1997 16:39:16 -0700
From: Russ Allbery <rra@stanford.edu>
To: smeyyappan@pyrasol.com
Subject: Re: Bus Error in ora_login
Message-Id: <m3wwl4y2xn.fsf@windlord.Stanford.EDU>
[ Posted and mailed. ]
smeyyappan <smeyyappan@pyrasol.com> writes:
> I successfully made oraperl v2.4 (Perl 4.036 and Oracle 7.3.2). But
> when I tried to do Make test, ora_login returns bus error. Can you tell
> me what's wrong?
I would recommend upgrading to Perl 5.004 and use the current Oracle Perl
modules. Perl 4.036 is buggy, unsupported, and ancient.
--
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print
------------------------------
Date: 30 Aug 1997 00:32:47 -0400
From: Les Schaffer <godzilla@futuris.net>
Subject: changing dir of parent shell
Message-Id: <m2wwl4thn4.fsf@futuris.net>
How do i get a perl script to change the directory i was just in to another one.
for example, i am in /home/foo.
i call my perl script entitled unpack:
/home/foo: > unpack
and when the script is done i am in a different dir:
/home/foo: > unpack
[ blah blah blah ]
/home/foo/bar: >
where bar is determined by unpack.
when i had unpack written as a bash script, i could go
/home/foo: > . unpack
[ blah blah blah ]
/home/foo/bar: >
is there an equivalent for perl?
much thanks
les schaffer
------------------------------
Date: Sat, 30 Aug 1997 02:46:42 GMT
From: dkcombs@netcom.com (David Combs)
Subject: Re: Compiling perl5.004.01 on solaris 2.5.1
Message-Id: <dkcombsEFpH1v.EGB@netcom.com>
In article <33FFE47B.72C9C94A@webspan.net>,
Youcai Chen <ReplyTo__ychen@webspan.net> wrote:
>Patrick McPartland wrote:
>
>> Hello,
>>
>> I am trying to get perl 5.004.01 to compile on solaris 2.5.1 with
>> gcc-2.7.2.2 . Configure writes the Makefile, runs make depend, then
>> fails make on util.c with this error:
>>
>> util.c: In function `Perl_form':
>> util.c:1107: number of arguments doesn't match prototype
When you find the answer, please post it (and also email
it to me too).
THANKS!
------------------------------
Date: Fri, 29 Aug 1997 20:02:18 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Help - Displaying text files!!!
Message-Id: <qer7u5.qvg.ln@localhost>
John Stanley (stanley@skyking.OCE.ORST.EDU) wrote:
: In article <01bb95da$f9ff7c20$5f867dc2@cathalmc>,
: Masked <Masked@Masked.Masked> wrote:
: >Hi. I'm new to Perl so please put up with my (perhaps silly?) question.
: >What I want to know is how do I write a script that will read from a text
: >or html file and then output it to the screen? I'd be delighted if you
: >could give me some sample code!
[ snip the first three ways ]
: 4.
: open( FILENAME, "<filename" ) || die "burble grok on open: $!\n";
: @wholefile = <FILENAME>;
: print "@wholefile";
^ ^ indent all but first line
[ snip 4a ]
: 4b.
: open( FILENAME, "<filename" ) || die "burble grok on open: $!\n";
: @wholefile = <FILENAME>;
: while( $_ = shift @wholefile ) {
: @chars = split //;
: print "@chars";
^ ^ strrrrretch ;-)
: }
[ snip three more ways ]
But using those double quotes around the array changes the output.
from perlvar:
-----------------------------------
=item $LIST_SEPARATOR
=item $"
This is like "C<$,>" except that it applies to array values interpolated
into a double-quoted string (or similar interpreted string). Default
is a space. (Mnemonic: obvious, I think.)
-----------------------------------
So, only seven ways, not nine.
That still ought to be plenty ;-)
--
Tad McClellan SGML Consulting
tadmc@flash.net Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 29 Aug 1997 19:39:39 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: how to set shell variable from perl?
Message-Id: <EFoxA3.E52@bcstec.ca.boeing.com>
In article <5t0cje$lfo$1@gte2.gte.net>, Tom <ii@fairhope.com> wrote:
>The following command works fine from the csh, but in perl it seems to
>be ignored.
>
>`setenv MYDIR "$HOME/foo" `
>
>Any suggestion?
>
Is something like this what you want:
use Env 'HOME';
$MYDIR = "$HOME/foo";
Note: this won't propagate $MYDIR back to your command shell though.
Hope this helps,
--
Charles DeRykus
ced@carios2.ca.remove_this.boeing.com
------------------------------
Date: Fri, 29 Aug 1997 21:05:07 -0400
From: Russ Smith <rsmith@tingley.net>
To: Bob lally <boblally@gte.net>
Subject: Re: indexed Search Engine
Message-Id: <340771C3.6AC1@tingley.net>
Check out the one at http://www.xav.com/scripts/index.html.
I haven't tried it, but it looks decent.
Russ
Bob lally wrote:
>
> Was wondering if anyone knows of a good perl based indexed search engine?
> I've searched the net and not found a thing.
>
> Thanks.
>
> Bob
------------------------------
Date: Fri, 29 Aug 1997 23:24:29 -0700
From: Howard Haisten <bhaisten@bellsouth.net>
Subject: Invalid Transmission error
Message-Id: <3407BC9D.23E1@bellsouth.net>
I'm new at cgi script configuration; I've looked through some "faq"
offerings and am unable to figure out what to do about the following
error message:
Invalid Transmission #3 received from: 32.96.65.181<br>If your
connection was interrupted, you must Enter the shop from the
beginning again.
I am attempting to configure "Perlshop" on my server. Repeated rechecks
of my configuration to the documentation/instructions is not revealing
the source of my glitch.
Any suggestions?
Thanks,
--
Howard Haisten
bhaisten@bellsouth.net
------------------------------
Date: 29 Aug 1997 16:42:21 -0700
From: Russ Allbery <rra@stanford.edu>
To: pellja@wwc.edu
Subject: Re: ipc socket as 0_NONBLOCK
Message-Id: <m3sovsy2si.fsf@windlord.Stanford.EDU>
[ Posted and mailed. ]
James Pellow <pellja@wwc.edu> writes:
> I have perl 5.004 and I am working on remote communications between two
> linux boxes (2.0.30 slackware 3.3). I have sucessfully created a socket
> connection in perl and it seems to work ok. So here is the problem: I
> need the program to be able to check the socket for data and if nothing
> is present to continue on to the next line. Currently the socket seems
> to be set up in blocking mode. I have read the source code for
> Socket.pm and IO::Socket.pm and the man pages for the linux system calls
> and it talkes about setting the socket up as O_NONBLOCK. Is it possible
> to do this in perl.
It sounds like what you really want to do is use the four-argument form of
select (see man perlfunc). But to answer your question:
use Fcntl qw(F_SETFL O_NONBLOCK);
[...]
fcntl ($socket, F_SETFL, O_NONBLOCK)
or die "unable to set socket nonblocking";
--
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print
------------------------------
Date: 29 Aug 1997 16:35:53 -0700
From: Russ Allbery <rra@stanford.edu>
To: gt1535b@acmey.gatech.edu (dmouse)
Subject: Re: module problems
Message-Id: <m367sozhnp.fsf@windlord.Stanford.EDU>
[ Posted and mailed. ]
dmouse <gt1535b@acmey.gatech.edu> writes:
> My next question is about variables. I have some variables that are
> assigned to (without being previously declared) within Scti::scti. It
> was my understanding that those variables would be visible to the main
> package as global package variables, which is what I want them to be.
> Is this correct?
Yes. If you assign to a variable $blah in the scope of package
Scti::scti, your main program can access that variable as
$Scti::scti::blah. If you want your main program to see it as $blah,
you'll need to export it.
--
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print
------------------------------
Date: Fri, 29 Aug 1997 21:00:32 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Joe Mosby <steve@mosby1.force9.net>
Subject: Re: New to the business!
Message-Id: <Pine.GSO.3.96.970829205602.2896E-100000@julie.teleport.com>
On Fri, 29 Aug 1997, Joe Mosby wrote:
> I have tried to play around with a few scripts to add my own functions
> and have done so quite succesfully with a chat script. Now I want to add
> a "Private Message" facility to this script.
> The problem I am having is that when I try to add this function it
> goes wrong.
That's a vague description, don't you think?
> I want it to have three sort of variables...1. If you sent
> the message you see "(You sent a private message to JDoe) The message"
> 2. If the message is to you "(JDoe sent a private message to you) The
> message" 3. You didn't send the message and it's not to you "JDoe is
> whispering".
I'm not sure why you call those "variables". I've never seen the word used
that way before. But I think I see what you want, and I don't see any
problem so far.
> I want the message to be made private by either looking like "/JDoe
> The message" OR "JDoe: The message" If anyone has any tips as to how to
> achieve this (I know it's a lot to ask, or it seems it to me!) I would
> be very grateful!
Could this be what you want?
$sender = 'JDoe';
$message = 'The message';
$output = "$sender: $message";
If that's not what you need, can you tell us how far have you gotten, and
where are you stuck? Good luck!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Fri, 29 Aug 1997 21:01:43 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: "Ronald L. Parker" <ron@farmworks.com>
Subject: Re: Out of memory problem
Message-Id: <Pine.GSO.3.96.970829210104.2896F-100000@julie.teleport.com>
On Fri, 29 Aug 1997, Ronald L. Parker wrote:
> On Fri, 29 Aug 1997 08:17:36 -0700, Tom Phoenix
> <rootbeer@teleport.com> wrote:
>
> >> undef $/;
> >> while(<TXT>){
> >> while(/\d+\s/gs){
> >
> >I don't think that the /s option adds anything there.
>
> I think the original poster intended for the /s to make \s match
> newline. (Doesn't it do that anyway?)
Yes, it does. That's why I don't think that the /s option adds anything
there. :-)
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 30 Aug 1997 00:34:39 GMT
From: michael@flash.net (Michael W Peterson)
Subject: Re: Perl & Shadow Passwords authentitacion.
Message-Id: <5u7pqv$jh3$1@excalibur.flash.net>
On Thu, 28 Aug 1997 14:33:06 -0400, John Osborne
<osborne6@acm.NOSPM.cps.msu.edu> wrote:
>
>On Thu, 28 Aug 1997, Tom Phoenix wrote:
>
>> On 28 Aug 1997, John Osborne wrote:
>>
>> > I've found that I can snag encrypted passwords from /etc/shadow using
>> > repeated calls to getpwent. Give it a try, it might work on your system.
>>
>> If you can do that from an unprivileged process, that pretty much negates
>> the usefulness of having shadow passwords, doesn't it? :-)
>>
>After I posted I did a few tests: It works under Solaris and SunOS.
>It doesn't work under FreeBSD. And I ran the script as a non root
>process. Perhaps Sun needs to fix Something That Is Broke(tm).
>
I'd like to see your script. I've yet to have script running on Solaris
2.5.1 return shadow passwords unless it's running privileged.
In fact, getpwnam (and family) doesn't even return the crypted password on
my Solaris boxen; it just returns the 'x'. I have to access the getspnam
routine through Shadows.pm[1] to get at the password entries.
[snip]
[1] I've forgotten where this came from. It wasn't on CPAN last I looked and
it's only tested on Solaris. Poke around in DejaNews if you're interested;
that's where I found it.
--
Michael W Peterson <http://www.flash.net/~michael/>
Senior System Administrator
FlashNet Communications <http://www.flash.net/>
"Unix: more than enough rope..."
------------------------------
Date: Fri, 29 Aug 1997 21:21:04 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Michael W Peterson <michael@flash.net>
Subject: Re: Perl & Shadow Passwords authentitacion.
Message-Id: <Pine.GSO.3.96.970829211151.2896J-100000@julie.teleport.com>
On 30 Aug 1997, Michael W Peterson wrote:
> I've yet to have script running on Solaris
> 2.5.1 return shadow passwords unless it's running privileged.
That's a relief. :-)
> In fact, getpwnam (and family) doesn't even return the crypted password
> on my Solaris boxen; it just returns the 'x'.
Well, there's a feature on my ISP's SunOS machines which is pretty cool.
getpw* returns "##rootbeer" (or whatever) as the crypted password. Then,
if you pass that to crypt along with a possible password for checking,
crypt returns that same "##rootbeer" string only if the password is
correct. Otherwise, you get the empty string.
The elegance of this system is that you can check passwords with exactly
the same crypt code you can use on machines without shadow passwords, so
user-level code can validate a password, but it never sees the crypted
password (or even the salt). (For the curious, it's all done with the help
of a root-level daemon, which the crypt system call talks to.)
It may be that this feature confused someone into thinking that their
system was giving out crypted passwords. But until we see some code and
output, it's just a guess. Cheers!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Fri, 29 Aug 1997 19:11:29 -0600
From: peterarm@r2tech.com
Subject: Perl for DOS: How do I reference long filenames?
Message-Id: <872899411.30468@dejanews.com>
Hi,
I'm using a port of Perl 4.19 for DOS.
I have a problem: How do I reference the long filenames that Win 95
uses?
(I want to get at a subdirectory of the "Program Files" directory.)
I've
tried /"Program Files"/, /Progra~1/, etc but I can't get it to work.
If it helps, here's most of the script I'm working on:
opendir(FINDPART,"c:/Windows/Profiles") || die "Couldn't open
c:\Windows\Profiles\n";
@allfiles = readdir(FINDPART);
foreach $_ (@allfiles) {
next if ( $_ eq "." || $_ eq ".." || -f $_ );
print "Copying to $_ StartMenu.\n";
opendir(FROM, "c:/Progra~1/FindPart") || die "Couldn't open
c:\Program
Files\FindPart\n";
die "FROM is not a directory\n" unless (-d FROM);
}
closedir(FP);
Thanks!
Peter Armstrong
(I know I'm a beginner at Perl)
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: Fri, 29 Aug 1997 05:36:59 -0700
From: Michael McGrattan <mcgrattm@cts.com>
Subject: Perl Pipes and FileHandles
Message-Id: <3406C26B.7580@cts.com>
I have a question regarding the 'piping' of output
via an 'open' command. Essentially I am invoking a
database connection using the database's proprietary command line
utility and I will be passing SQL commands through
the file handle. My problem lies in effeciently capturing
to database output into a buffer or filehandle. Presently
I am 'piping' the output to another perl script which
uses 'while (<>)' to process the stream and load a buffer.
However I want to avoid invoking another perl script and
would rather load a buffer in the subroutine and pass
that back to the calling routine. Below is an example of
what I am trying to do. I am using 'sh' for the sake of
the example, but this is where I would be invoking the
database utility and the following 'print XXX "..."' is
where I would I would be passing the database commands.
I can not find another way besides invoking the second
perl script (catcher.pl) to capture the data.
----------------------
#!/export/home/local/bin/perl
use English;
&getTest;
sub getTest
{
open(XXX,"| sh | catcher.pl");
print XXX "echo 'this is a test1'\n";
print XXX "echo 'this is a test2'\n";
print XXX "exit\n";
#I DO NOT WANT TO INVOKE ANOTHER SCRIPT TO
#TO HANDLE THE OUTPUTSTREAM. I WOULD LIKE TO DO
#SOMETHING LIKE:
#open(XXX,"| sh | @buffer");
#OR
#open(XXX,"| sh | $fileHandle");
#SO THAT I CAN BE ABLE TO LOOP THROUGH AND
#PROCESS THE BUFFER OR FILE HANDLE LATER
#IN THE PROGRAM AND MANIPULATE THE INDIVIDUAL
#OUTPUT ELEMENTS. BUT HOW DO YOU DO THIS WITHOUT
#INVOKING ANOTHER SCRIPT TO CATCH THE STREAM?
#IDEALLY ALL OF THE OUPUT WOULD BE PIPED TO A
#BUFFER. THEN I COULD PASS THIS BUFFER BACK TO
#THE CALLING ROUTINE OR ANOTHER SUBROUTINE.
close XXX;
}
-------------catcher.pl--------------
#!/export/home/local/bin/perl
use English;
while (<>)
{
push @buffer, $_;
}
$cnt=1;
foreach $element (@buffer)
{
print "LINE $cnt: $element";
$cnt+=1;
}
---------
Any comments/suggestion/solutions on a better method
of capturing output would be very much appreciated.
Thank you
Michael McGrattan
------------------------------
Date: 30 Aug 1997 04:21:58 GMT
From: twod@not.valid
Subject: PERL,file locking, vipw & Solaris2.5.1
Message-Id: <5u8756$74h$1@vnetnews.value.net>
Hi,
X-posted to comp.lang.perl.misc and comp.unix.solaris
I'm trying to write a PERL script that is to update the /etc/passwd or
/etc/shadow file directly and am having a tad of trouble trying to replicate
the locking mechanisms used by Solaris.
What I am trying to do is lock the file(s) in the same manner as the 'vipw'
program. That is to say that if I have vipw running in one session that the
PERL script can detect this and exits and when the PERL script has the file
locked the vipw fails with the message 'vipw: /etc/passwd file busy', which
is normally seen when you try to start a second vipw session when another
has acquired the lock.
I can't seem to find a lock file in the expected places under Solaris and I
can't seem to find the correct method of opening the file under PERL - I've
tried open(), sysopen(), fnctl(), and ioctl() in various combinations and
can't seem to crack it :(
Has anyone got an example of how to do this ?
TIA
IAP
--
In an attempt to reduce junk email I use an invalid 'From' address.
My correct email address can be determined by replacing 'not.valid' with with
'value.net'
------------------------------
Date: 29 Aug 1997 16:41:01 -0700
From: klander@primenet (Kevin)
Subject: perldoc
Message-Id: <34075c69.112970172@news.primenet.com>
Howdy.
I just installed perl5.00401, and I'm having trouble with perldoc. I
type 'perldoc IO::Socket', and after a few seconds it tells me it
can't find documentation for IO::Socket. Also, if I use the -v flag
to get information about where it's searching, I get a segmentation
fault. Is there any documentation on IO::Socket? If so, where would
perldoc be looking for it? The man page doesn't say where besides the
PATH and PERL5LIB paths it searches. Also, why would I be getting a
segmentation fault when I use -v? Thanks for any help...
--
Kevin -- klander at primenet dot com (add the .com in email replies)
http://www.primenet.com/~klander
--
------------------------------
Date: 29 Aug 1997 16:43:14 -0700
From: Russ Allbery <rra@stanford.edu>
To: joel@aracnet.com (Joseph Look)
Subject: Re: rsh a Perl script
Message-Id: <m3oh6gy2r1.fsf@windlord.Stanford.EDU>
[ Posted and mailed. ]
Joseph Look <joel@aracnet.com> writes:
> I have experienced a problem when I tried to run a perl script through
> rsh. I think the problem is when I waiting for an input. For example,
> the following script will not print the first three line until a return
> is pressed when you run it through rsh.
Unbuffer stdout in your Perl script so that the operating system doesn't
helpfully buffer output and then flush at odd times.
$| = 1;
--
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print
------------------------------
Date: Fri, 29 Aug 1997 20:54:32 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Joseph Look <joel@aracnet.com>
Subject: Re: rsh a Perl script
Message-Id: <Pine.GSO.3.96.970829205401.2896D-100000@julie.teleport.com>
On 29 Aug 1997, Joseph Look wrote:
> I have experienced a problem when I tried to run a perl script through
> rsh. I think the problem is when I waiting for an input. For example,
> the following script will not print the first three line until a return
> is pressed when you run it through rsh.
Sounds like buffering. Have you tried the magical $| variable? Hope this
helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 30 Aug 1997 00:45:22 -0400
From: Douglas McNaught <doug@ono.tc.net>
Subject: Re: rsh a Perl script
Message-Id: <m267sol1nh.fsf@ono.tc.net>
Tom Phoenix <rootbeer@teleport.com> writes:
> On 29 Aug 1997, Joseph Look wrote:
>
> > I have experienced a problem when I tried to run a perl script through
> > rsh. I think the problem is when I waiting for an input. For example,
> > the following script will not print the first three line until a return
> > is pressed when you run it through rsh.
>
> Sounds like buffering. Have you tried the magical $| variable? Hope this
> helps!
It might also be the rsh wackiness that makes it read from stdin even
if the remote program doesn't. I would try 'rsh -n'.
-Doug
--
sub g{my$i=index$t,$_[0];($i%5,int$i/5)}sub h{substr$t,5*$_[1]+$_[0],1}sub n{(
$_[0]+4)%5}$t='encryptabdfghjklmoqsuvwxz';$c='fxmdwbcmagnyubnyquohyhny';while(
$c=~s/(.)(.)//){($w,$x)=g$1;($y,$z)=g$2;$w==$y&&($p.=h($w,n$x).h($y,n$z))or$x==
$z&&($p.=h(n$w,$x).h(n$y,$z))or($p.=h($y,$x).h($w,$z))}$p=~y/x/ /;print$p,"\n";
------------------------------
Date: 30 Aug 1997 02:12:08 GMT
From: kerr@cs.uregina.ca (Andrew Kerr)
Subject: Script to change passwd... questions on how
Message-Id: <5u7vho$mbc$1@sue.cc.uregina.ca>
Okay, I'm not quite a newbie to perl, but I'm no expert.
I have written the code to interface with the page, verify that
the username exists, the password matches the one in the /etc/passwd
file (BTW this is on a UNIX, well Linux, system), etc.
Now I'm ready to actually change the password.
Any suggestions??? I could just do a call to /usr/bin/passwd
but then how when it prompts do I feed it the current password
and then the new password????
Any help greatly appreciated.
Andrew
--
Andrew Kerr
Email: kerr@tdi.uregina.ca
Alternate: kerr@3co.com
Homepage: http://tdi.uregina.ca/~kerr/index.html
Journalism is literature in a hurry. -- Matthew Arnold
------------------------------
Date: 28 Aug 97 10:31:55 GMT
From: "Nino Fioretti" <ninofior@adel.tafe.sa.edu.au>
Subject: Re: Setting the TZ time variable within Perl
Message-Id: <01bcb39d$26aadae0$c8855c8f@ninofior>
Follow up...
The perl code I am using to get the date is as follows:
$ENV{'TZ'} = "CST-9:30CDT";
($sec,$min,$hour,$mday,$mon,$year,$wday) =
(localtime(time))[0,1,2,3,4,5,6];
$time = sprintf("%02d:%02d",$hour,$min);
The $ENV{'TZ'} = "CST-9:30CDT"; line is my attempt at using my own local
time rather than the web server's time which is in a differnet time zone.
However it does not seem to make any difference. I have also tried using
the gmtime function.
Any ideas or suggestions would be appreciated.
Regards
Nino
Nino Fioretti <ninofior@adel.tafe.sa.edu.au> wrote in article
<0214259b$7520ee40$c8855c8f@ninofior>...
> My web server is located in a different time zone to me and when my
various
> CGI scripts send email I get the local Web Server time. Can someone tell
me
> how I can set a different time setting to the one in the server. The
server
> has an environment variable TZ=EST5EDT, whilst my local time has a
setting
> TZ=CST-9:30CDT.
> How can I make this setting from within a CGI script?
------------------------------
Date: Fri, 29 Aug 1997 19:18:51 -0500
From: Devon Caines <devonc@inetnebr.com>
Subject: Simple Question on grep
Message-Id: <3407656C.56DF3D06@inetnebr.com>
Hey guys,
simple question that confusing me.
foreach (@new) {
chop;
@removed = grep(!/$_/,@old);
}
isnt the above supposed to place everything from @new
thats not in @old in @removed?
this never seems to work.. even when I test both lists
just before the loop to ensure that they do contain
slightly dissimilar info.
WHAT AM I DOING WRONG?
Thanks
Devon
--
--------------------------------------------------------------
C'ing is leaving the BASIC's behind | devonc@inetnebr.com |
C++ ing walking by faith and not by sight): | |
--------------------------------------------------------------
------------------------------
Date: Fri, 29 Aug 1997 21:08:09 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Devon Caines <devonc@inetnebr.com>
Subject: Re: Simple Question on grep
Message-Id: <Pine.GSO.3.96.970829210402.2896H-100000@julie.teleport.com>
On Fri, 29 Aug 1997, Devon Caines wrote:
> foreach (@new) {
> chop;
> @removed = grep(!/$_/,@old);
> }
Whoops! Within the conditional of a grep, $_ is aliased to the current
element from the list. So that pattern match is taking the current element
as a pattern, and matching that against the current element!
> isnt the above supposed to place everything from @new
> thats not in @old in @removed?
Nope. That sounds as if you want to find the difference between two
arrays.
http://www.perl.com/CPAN/doc/FAQs/FAQ/html/perlfaq4/
How_do_I_compute_the_diference_.html
Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 29 Aug 1997 17:25:41 -0700
From: Scott Henry <scotth@sgi.com>
Subject: Re: sockets on IRIX?
Message-Id: <yd8n2m0ldoa.fsf@hoshi.engr.sgi.com>
>>>>> "c" == (classified) <nocturne@iastate.edu> writes:
c> I am trying to write a perl program that uses sockets to query a web
c> server. The socket code comes almost straight from the camel book. It
c> works fine on ULTRIX and OSF/1, but on Irix it dies when creating the
c> socket. Anyone have any insights? the code is below...
1) which release of IRIX?
1a) which version of Perl?
2) don't hard-code network constants! Get them from the correct
include file/module. They vary between OSes.
--
Scott Henry <scotth@sgi.com> / Help! My disclaimer is missing!
IRIX MTS, / GIGO *really* means: Garbage in, Gospel Out
Silicon Graphics, Inc / http://reality.sgi.com/scotth/
------------------------------
Date: Fri, 29 Aug 1997 19:19:32 -0400
From: ken@forum.swarthmore.edu (Ken Williams)
Subject: split() on an empty string
Message-Id: <ken-2908971919320001@news.swarthmore.edu>
Hi-
There's a behavior that I don't like in the split() function, and seems to
contradict the documentation (from new Camel book):
"If the PATTERN doesn't match at all, split() returns the original
string as a
single substring."
Here's where that's not true:
@array = split(/not_here/, '');
The result: @array is set to (), rather than ('') as the above statement
would indicate.
I know that split() is a funny function with lots of exceptions to its
rules, but I can't find any documentation that explains this one. I would
really like it if this bug were fixed (or feature taken away), because as
the function is now, it necessitates special cases in my code.
If anyone can tell my why this behavior happens, it would at least
reassure me a little bit.
-Ken Williams
The Math Forum
ken@forum.swarthmore.edu
------------------------------
Date: Sat, 30 Aug 1997 00:41:50 GMT
From: over@the.net (dave)
Subject: Re: struct in perl
Message-Id: <34076a49.9721065@news.one.net>
bill <bill@dml0.wcupa.edu> wrote:
>okay, sorry if this is a stupid question, but how do i do a struct in
>perl? i don't want to use the pack/unpack stuff 'cause i don't want to
>have to do that for each record i look at. i just want to be able to
>say...
>array_of_recs[i].first_name = "bill";
>
>i'm using c for this program but i'd rather use perl because perl is so
>much easier than c (plus i don't know how to glob a file in c...
>@file=<FILE>;)
>
>so, is this something i overlooked in the llama book or is it not there?
>
>any info would be appreciated.
>
>bill
Try using an array of references to "anonymous" hashes instead.
I think hashes are a big reason perl is much easier than C. Hashes
don't have to be homogenous. I.E. each record need not have the
same element configuration. Once you get used to this you
might be cursing C structures :)
You will need a book covering perl 5 or check the man pages.
Dave
|
| Please visit me at http://w3.one.net/~dlripber
|
| For reply by email, use:
| dlripber@one.net
|________
------------------------------
Date: Fri, 29 Aug 1997 21:03:21 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: bill <bill@dml0.wcupa.edu>
Subject: Re: struct in perl
Message-Id: <Pine.GSO.3.96.970829210213.2896G-100000@julie.teleport.com>
On Fri, 29 Aug 1997, bill wrote:
> okay, sorry if this is a stupid question, but how do i do a struct in
> perl?
Usually, this sort of thing is done with a hash. (The exception is when
you're passing values to code written in another language, for example,
and need to use pack.)
Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Fri, 29 Aug 1997 19:45:46 -0400
From: ken@forum.swarthmore.edu (Ken Williams)
Subject: Re: When to use "use strict"
Message-Id: <ken-2908971945460001@news.swarthmore.edu>
Yes-
I'm also a happy user of mod_perl for Apache, and I can verify that 'use
strict' has probably saved me MUCHO development time, judging by the
amount of time I've had to spend hunting down bugs that happened when I
_didn't_ 'use strict'.
The way I see it, for any project of significant size, you want to always
know _exactly_ which variables you're using as globals (as few as
possible). If you accidentally mess up and forget to declare a variable
somewhere as a lexical, you have two choices:
- if you 'use strict', the compiler will tell you where you messed up
- if you don't 'use strict', your variable may leak all over the place and
you'll have a big mess on your hands.
In article <Pine.GSO.3.96.970827074330.1757H-100000@julie.teleport.com>,
Tom Phoenix <rootbeer@teleport.com> wrote:
>On Wed, 27 Aug 1997, Scott Wimer wrote:
>
>> My assumption was that the my variables were in stored internally in
>> list format, and would therefore be much faster than haveing to do the
>> hash calculations, if you did not have an enormous number of my()'d
>> variables in each block.
>
>Even if you do have an enormous number of my() variables, they're faster
>than globals. The compiler turns $lexical into code which points right at
>it, as I understand.
>
>> As to `use strict': I turn it on for script development and while I'm
>> working on fine tuning stuff, but after that, I turn it off. That way
>> I don't pay the small performance penalty when the code is in
>> production.
>
>Do you also carry the baby in the trunk so that you won't pay the
>not-so-small performance penalty of strapping it into a car seat? :-)
>
>Seriously, use strict has three parts. As I understand things, 'vars'
>should have essentially no performance penalty, 'subs' should have
>essentially no performance penalty, and 'refs' should have essentially no
>performance penalty. :-) If you find that 'use strict' slows your
>real-world program by enough to notice (say, one-tenth of a second), I'd
>say that something is seriously wrong. (If it speeds things up, on the
>other hand... :-)
>
>Now, if you're writing CGI scripts and worrying that they may be
>called hundreds of times per minute, there might be a reason to want to
>shave every millisecond. That is, if it weren't for the excellent mod_perl
>for Apache, which eliminates much bigger overhead costs such as loading
>delay and internal compile time. From what I've seen, I'd expect it to
>make a typical CGI script of mine run on the order of 20 (!) times faster.
>
>Hope this helps!
>
>--
>Tom Phoenix http://www.teleport.com/~rootbeer/
>rootbeer@teleport.com PGP Skribu al mi per Esperanto!
>Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
-Ken Williams
The Math Forum
ken@forum.swarthmore.edu
------------------------------
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 950
*************************************