[7742] in Perl-Users-Digest
Perl-Users Digest, Issue: 1367 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 25 21:07:26 1997
Date: Tue, 25 Nov 97 18:00:22 -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 Tue, 25 Nov 1997 Volume: 8 Number: 1367
Today's topics:
[Q] Can't Listen w/ IO::Socket under GlibC ()
Re: ASN.1 format to Perl? <ghowland@hotlava.com>
Re: Cron <qdtcall@esb.ericsson.se>
Executing an external command from a Perl CGI <bdg3@pge.com>
Re: Finding the longest common prefix over a list of st (Abigail)
Re: How do you export a variable from module? <rootbeer@teleport.com>
How to execute CGI script written in perl on NT server? <drive@mbox4.singnet.com.sg>
Re: How to execute CGI script written in perl on NT ser (Vladimir Sovetov)
Re: How To Test if number is ODD or EVEN? (Vladimir Sovetov)
Re: interpreted languages (Donal K. Fellows)
Killing system calls from within perl <alex@online.emap.com>
Re: Killing system calls from within perl <zenin@best.com>
launch a child process in a cgi <delaval@cedocar.fr>
Re: Message Board Scripts Help <mweber@atlas.de>
Re: Moving/Renaming files (Mike Stok)
Re: New to perl. What's wrong with this script? <kperrier@Starbase.NeoSoft.COM>
Re: nt build of perl5.004_04 (Jeremy D. Zawodny)
ntperl newbie <coke@mindless.com>
Re: Perl script making CPU idle time 0. <jamesr@aethos.co.uk.nospam>
Re: piping output of multiple files (E.None Archibald)
print (...) interpreted as function (Alexander Farber)
Re: simple pipe question <qdtcall@esb.ericsson.se>
Re: sum in assoc array (Greg Bacon)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 24 Nov 1997 16:19:00 GMT
From: nicholas@neko.binary9.net ()
Subject: [Q] Can't Listen w/ IO::Socket under GlibC
Message-Id: <slrn67ja7d.47q.nicholas@neko.binary9.net>
After redesigning my Linux system to use Glibc 2.0.5c, I've found that
I can no longer use IO::Socket to create & listen to a udp(or tcp) socket.
When I strace my program, I see something like:
bind(3, ....) = 0
listen(3,1) = -1 EOPNOTSUPP (Operation Not Supported)
A simple program like:
#!/usr/bin/perl
use IO::Socket;
$sock=new IO::Socket::INET(Listen=>1,Proto=>'udp',LocalAddr=>'neko',
LocalPort=>2122);
--end--
fails in this exact same way. I've tried using the IO::Socket that comes with
Perl5 (btw, Perl5.004_04) and I've tried install the IO::Socket module from
CPAN (ala 'install IO::Socket') to no avail.
If I use the IO::Socket module to create a tcp socket that _isn't_ being
listened to, it works just fine. Only when I pass Listen=>1 to IO::Socket
does the trouble begin.
This is under a Linux 2.1.66(pre,actually) w/ glibc 2.0.5c and gcc 2.7.2.3.
At this point I don't know how to further debug this. Everything was cool
under libc5, and nothing else appears amiss in my system (at least on
the networking level).
This is a rather important thing that I need and I would like some pointers
in how to approach debugging this.
Thank you!
--
___________________________________________________________________________
simple is elegant nicholas@binary9.net
___________________________________________________________________________
------------------------------
Date: Tue, 25 Nov 1997 09:59:44 +0100
From: Gary Howland <ghowland@hotlava.com>
To: Al Wang <alwang@NOSPAMdoubt.com>
Subject: Re: ASN.1 format to Perl?
Message-Id: <347A9380.5E78@hotlava.com>
Al Wang wrote:
>
> Hi,
>
> I'm looking to import data encoded in ASN.1 to a local relational
> database, and I'm wondering whether anyone knows of any software tools
> that might help. Specifically, I'd like an ASN.1 compiler that
> translates the data into Perl data structures. I've seen lots of
> similar programs for ASN.1 to C, but I'd much prefer to work in Perl.
>
> Or, if there is a good emthod to convert ASN.1 to delimited-text
> files, that would be helpful too.
Graham Barr's Convert::BER is an excellent module for encoding and
decoding BER data. It doesn't parse the ASN1, however, but it's
relatively easy to do this by hand for a small number of types.
Gary
--
pub 1024/C001D00D 1996/01/22 Gary Howland <gary@hotlava.com>
Key fingerprint = 0C FB 60 61 4D 3B 24 7D 1C 89 1D BE 1F EE 09 06
------------------------------
Date: 25 Nov 1997 09:59:13 +0100
From: Calle Dybedahl <qdtcall@esb.ericsson.se>
Subject: Re: Cron
Message-Id: <isyb2de4da.fsf@godzilla.kiere.ericsson.se>
Todd Smith <nospam.tbsmith@mindspring.com> writes:
> Can someone tell me what this is, how to use it, and where to get it?
cron is a utility found on just about any Unix system in existence. It
has nothing whatsoever to do with Perl, except that perl scripts are
sometimes run by it. Go get a beginners guide to Unix, it'll most
probably tell you what you need to know. FAQs for Unix-specific
newsgroups might be helpful as well.
--
Calle Dybedahl, UNIX Sysadmin
qdtcall@esavionics.se http://www.lysator.liu.se/~calle/
------------------------------
Date: Tue, 25 Nov 1997 02:04:07 -0800
From: Billy Glenn <bdg3@pge.com>
Subject: Executing an external command from a Perl CGI
Message-Id: <347AA297.32C09ED6@pge.com>
Fellow Perl Hacks-
I've been on a binge of developing Perl CGI interfaces for routine
administration tasks on many of our infrastructure unix systems. In
each of these cases (things ranging from kicking off an RDIST job to
push an update to a web server, user and paging service administration,
adding and deleting records from DBM database files), the task which
ALWAYS causes me grief is executing external commands (i.e. running
another script, executing a command line, etc). In one case (my
earliest CGI, written 'the hard way') I ended up having to fork off
another process to run the RDIST. Then I discovered cgi-lib.pl, and
created a few more admin tools. This time I was finally able to make it
work by simply doing a:
print `/usr/local/bin/myscript.pl`;
Now, my newest effort (since discovering the JOYS of CGI.pm!!)
incorporates many of the previous functions, and needs to invoke several
external commands. I've tried using system like this:
system ("/usr/local/db2file.pl");
as well as the previously shown 'backtick' method. Obviously I don't
want to 'exec', as I want to retain control of the flow of execution.
Ideally, I would like the invocation to return the output of the called
script (i.e. $output = `/usr/local/db2file.pl`;) so that I could later
use this output in my HTML.
I'm not sure why this is so difficult - in a regular Perl script both of
the methods above seem to work (some of the tools started as
command-line scripts before they were CGIs). I've unbuffered standard
out to no avail - and really don't want to deal with the mess of forking
of a new process (which caused it's own set of difficulties ;-) if I can
help it.
I've pored over both the camel book and 'Advanced CGI Programming', as
well as everything I can read about CGI.pm - but nothing seems to help
me with this (embarassingly simple-seeming) problem! Since it seemed
like my results varied as I began using cgi-lib.pl, and then CGI.pm, I'm
wondering if these might be effecting the way external commands are
executed. In my CGI.pm scripts, I'm using the 'standard' methods as
follows:
use CGI qw(:standard);
Any suggestions, comments, or examples are greatly appreciated. If
anyone has specific questions regarding my code or would like to see
full examples demonstrating the problem, I will be happy to provide
whatever is necessary to help resolve this pesky problem..
Thanks in advance, and have a great day!
Billy Glenn
Sr. Network Specialist - Internet Services
Pacific Gas & Electric Co.
bdg3@pge.com
------------------------------
Date: 24 Nov 1997 18:33:07 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Finding the longest common prefix over a list of strings
Message-Id: <slrn67ji6k.b3.abigail@betelgeuse.wayne.fnx.com>
Mark Mielke (markm@nortel.ca) wrote on 1545 September 1993 in
<URL: news:lq17m9zxofz.fsf@bmers2e5.nortel.ca>:
++ abigail@fnx.com (Abigail) writes:
++ > Tushar Samant (scribble@shoga.wwa.com) wrote on 1545 September 1993 in
++ > ++ >Perl's regex is *still* faster than Ilya's algorithm though, but only
++ > ++ >by a few percent.
++ > Let's analyze it a bit further, before we drop to conclusions, shall we?
++
++ > ++ >So, now there's a different question. Given the fact that this new
++ > ++ >algorithm is just about as fast as the regex approach, which would you
++ > ++ >rather use/maintain? Here's the regex again:
++ > ++ > (join(',', @words).',') =~ /^(\w*)\w*,(\1\w*,)*$/;
++ > [ cool interesting proof that in theory Ilya's algorithm is much faster ]
++
++ > Clearly, Ilya's algorithm beats the regex hands down.
++ > I am almost certain that with a bit more careful analysis, I would
++ > be able to proof that Ilya's algorithm (with Tushar's suggestion) is
++ > linear (and hence optimal) in the size of the input.
++
++ I think the difference is that the regexp code is written in optimized C.
++ Ilya's may be more efficient in theory, but in practice it may be the same
++ speed (or a tad slower) because it is written in interpreted perl.
No, Ilya's will be more efficient in practise as well. The fact the
regex code is written in optimized C just means the input size where
it becomes slower is a bit larger.
++ What about if Ilya's algorithym was implemented in an XS code? :-)
Would not change the complexity.
++ > Any program that needs to be maintained probably needs to be
++ > efficient too. So, there would be no place for the regex.
++ > (The regex is much cuter though.)
++
++ This is true. I particularly foundthe:
++ perl -wle 'print "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/'
++ at the end of your posts intriguing... but after thinking about it
++ for a while i realized that although it may be efficient for the first call,
++ it doesn't do any prime number caching for the second, third etc. call...
++ so it's kinda useless :-)
It extremely inefficient. It's exponential in the input size.
++ > No need for a benchmark I would say.
++
++ If you want raw speed... the benchmark way IS the way to go :-) If you
++ care about maintenance/portability/etc... stick to the theory and use
++ algorithyms that have a much clearer/obvious approach. You may not be
++ the last maintainer of your code... :-)
If you can't do an analysis of an algorithm, how can you interpret
the outcome of benchmarks? Or do you always know all the possible
inputs beforehand?
Abigail
--
perl -wle 'print "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/'
------------------------------
Date: Mon, 24 Nov 1997 10:35:32 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Alexander Farber <eedalf@eed.ericsson.se>
Subject: Re: How do you export a variable from module?
Message-Id: <Pine.GSO.3.96.971124103123.24464K-100000@usertest.teleport.com>
On 24 Nov 1997, Alexander Farber wrote:
> i am trying to write a simple module, and it works fine
> with functions, but i cant figure out, how do i also export
> a global variable.
Do you find out when you type 'perldoc Exporter'? :-)
I think what you want is to, first, fix your module to 'use strict'. If
you declare your exportable variable with 'use vars' and follow the
instructions in the perlmod manpage, it should work. 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/
Ask me about Perl trainings!
------------------------------
Date: 24 Nov 1997 10:20:51 GMT
From: "Drive" <drive@mbox4.singnet.com.sg>
Subject: How to execute CGI script written in perl on NT server?
Message-Id: <01bcf8c1$60f3d3a0$36c815a5@poon>
Hi everybody,
Am new in writing CGI scripts and therefore need help badly in advising me
how to execute my script written in perl on an Windows NT server......
I have tested my script by calling it from the browser and it works fine.
But I am not sure of how to call it from my html file which will need to
execute the script whenever anybody enters that particular page. Hence, I
can't use Get or POST?
My script is as follows :
#!usr/local/bin/perl
$basedir = "g:\\drive\\cgi-bin";
$countfile = "count.txt";
$page = "My main page";
# Start of the counter log
print "Content-type: text/plain\n\n";
&lock_file;
exit;
#################################################
# Locks the counter log file
#################################################
sub lock_file {
open(LOG, "<$basedir/$countfile");
flock(LOG, 2);
&format_count;
&write_count;
close (LOG);
flock (LOG,8);
}
#################################################
# Processes the format of the hits saved
#################################################
sub format_count {
while (<LOG>) {
chop;
($file, $count) = split(/:/, $_);
$counts{$file} = $count;
}
}
#################################################
# Writes the number of hits to counter log
#################################################
sub write_count {
$counts{$page}++;
seek(LOG, 0, 0);
# Write the counts back to the file.
foreach $file (keys %counts) {
print LOG $file, ":", $counts{$file}, "\n";
}
}
Pls advise. Thank you so much!
Rgds,
Candice
drive@mbox4.singnet.com.sg
------------------------------
Date: 24 Nov 1997 10:41:27 GMT
From: sova@kpbank.ru (Vladimir Sovetov)
Subject: Re: How to execute CGI script written in perl on NT server?
Message-Id: <65blkn$8jp$1@home.kpbank.ru>
Drive (drive@mbox4.singnet.com.sg) wrote:
: Hi everybody,
: Am new in writing CGI scripts and therefore need help badly in advising me
: how to execute my script written in perl on an Windows NT server......
: I have tested my script by calling it from the browser and it works fine.
: But I am not sure of how to call it from my html file which will need to
: execute the script whenever anybody enters that particular page. Hence, I
: can't use Get or POST?
Well, the simplest way to do it is to use SSI, just add to your
HTML code line
<!--#exec cgi="/cgi-bin/your_script.cgi" -->
If you're not allowed to have sort of .shtml files on your server.
Then exists a "hackers way to do it"
<IMG ALIGN=right BORDER=0 SRC="/cgi-bin/your_script.cgi" width=1 height=1>
----
Vladimir Sovetov | Kuzbassprombank
------------------------------
Date: 25 Nov 1997 09:43:37 GMT
From: sova@kpbank.ru (Vladimir Sovetov)
Subject: Re: How To Test if number is ODD or EVEN?
Message-Id: <65e6k9$4ql$1@home.kpbank.ru>
Ken Fox (fox@pt0204.pto.ford.com) wrote:
: jay@dixonssurgical.co.uk (Jay Dixon) writes:
: > I want to test if a variable is Odd (or Even)
%cat odd
#!/usr/bin/perl5
@a = (1 .. 10 );
foreach ( @a )
{
if ( $_ % 2 )
{
print "$_ - Odd\n";
}
else
{
print "$_ - Even\n";
}
}
%./odd
1 - Odd
2 - Even
3 - Odd
4 - Even
5 - Odd
6 - Even
7 - Odd
8 - Even
9 - Odd
10 - Even
------------------------------
Date: 25 Nov 1997 10:23:36 GMT
From: fellowsd@cs.man.ac.uk (Donal K. Fellows)
Subject: Re: interpreted languages
Message-Id: <65e8v8$as8$1@m1.cs.man.ac.uk>
In article <65d243$im0$1@newsie2.cent.net>, JRM <emergent@cape.com> wrote:
[ Talking about MIT Scheme ]
> But they forgot to either ``SF'' or compile it.
Is SF supplied with MIT Scheme, or at least mentioned in the
documentation that comes with it? If not, how were they supposed to
figure out how to get it past _your_ stringent tests for "validity"
> They weren't benchmarking compilers, so you might argue that they
> shouldn't have used the compiler (but why did they include compiled
> C?), but neglecting to run SF on the ``script'' causes a performance
> hit because MIT Scheme doesn't assume that any built-in procedures
> are not redefined.
They probably included compiled C because it was easy to do, providing
something against which to compare the rest of the figures. Not
everyone has a C interpreter installed conveniently, but C compilers
are ubiquitous in the programming community...
Donal.
--
Donal K. Fellows http://r8h.cs.man.ac.uk:8000/ fellowsd@cs.man.ac.uk
Department of Computer Science, University of Manchester, U.K. +44-161-275-6137
--
Have you hugged a software engineer today?
------------------------------
Date: Tue, 25 Nov 1997 03:41:37 -0600
From: Alex Schajer <alex@online.emap.com>
Subject: Killing system calls from within perl
Message-Id: <880450490.1531@dejanews.com>
Hi,
I have a script that kills the web server everytime the load gets above
10. I measure the load by using `UPTIME`. However we would like to know
more information as to why the load has got so high. I thought about
doing `TOP` after the load is over 10. However when I run TOP it goes on
forever until I kill it from another window. Is there anyway of killing
TOP from within perl?
Thanks
Alex
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: 25 Nov 1997 10:24:44 GMT
From: Zenin <zenin@best.com>
Subject: Re: Killing system calls from within perl
Message-Id: <880453673.742306@thrush.omix.com>
Alex Schajer <alex@online.emap.com> wrote:
: I have a script that kills the web server everytime the load gets above
: 10. I measure the load by using `UPTIME`. However we would like to know
: more information as to why the load has got so high. I thought about
: doing `TOP` after the load is over 10. However when I run TOP it goes on
: forever until I kill it from another window. Is there anyway of killing
: TOP from within perl?
perldoc -f fork
perldoc -f exec
perldoc -f waitpid
perldoc -f kill
--
-Zenin
zenin@best.com
------------------------------
Date: Tue, 25 Nov 1997 10:55:26 +0100
From: xavier <delaval@cedocar.fr>
Subject: launch a child process in a cgi
Message-Id: <347AA08D.78D09513@cedocar.fr>
Hello everybody,
In one of my perl cgi script I have to read a form, execute a child
process and return a information page on the browser.
I'm using : system("the command to run"); and my script wait for this
child process to terminate and display the information page. But I don't
want to wait for the child. I want to execute the process in background
and display the information page before the end of this process. I tried
: system("command to run &") but it doesn't change anything.
Please help me !!!
Xavier (delaval@hotmail.com)
------------------------------
Date: Tue, 25 Nov 1997 08:20:41 +0100
From: "Mathias-H. Weber" <mweber@atlas.de>
Subject: Re: Message Board Scripts Help
Message-Id: <347A7C49.22CE7B4D@atlas.de>
Evan Connor wrote:
>
> I am a Web Designer who has undertaken the task of adding Matt's Script
> Archive Message Board to a client site I am developing (even though I am
> not a PERL programmer.)
I guess you mean a script taken from
http://www.worldwidemart.com/scripts/
You should keep in mind that there might still be people who
do not know Matt!
>
> I am having problems with the CGI file on the server. I get a server
> config error whenever I try to post a test message. If anyone is
> willing to help me install this or at least talk me through the process,
> I would gladly repay you by doinf some advanced HTML or graphic for you
> in return. Plus, I will publicly thank you for your help.
>
A common mistake with cgi-scripts that write to files on the server side
is
not to set the file permissions correctly. The cgi-script normally runs
as user "nobody" (are one of its relatives). So the files the scripts
writes to must have write permissions for this user. The easiest way to
overcome the problem is to give a
chmod +w <file>
with <file> naming all files the script tries to write to.
Hope this helps,
Mathias
--
__________________________________________________________________
| Dr. Mathias-H. Weber --- mailto:mweber@atlas.de |
| STN ATLAS ELEKTRONIK GmbH {~@_@~} |
| Brueggeweg 54 / Dept ETS21 _( Y )_ Phone: +49 421 457 4401 |
| 28305 BREMEN (:_~*~_:) Fax : +49 421 457 3177 |
| Germany (_)-(_) Telex: 2 457 460 |
___________________________SIGSIG: Signature too long (core dumped)
------------------------------
Date: 24 Nov 1997 18:38:48 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Moving/Renaming files
Message-Id: <65chjo$2gn@news-central.tiac.net>
In article <65cggb$8h2$1@mercury.psd.k12.co.us>,
J. Paul Reed <preed@psd.k12.co.us> wrote:
>Hello All!
>
>This may sound like a really stupid question (yeah, I even feel dumb
>asking it), but what's the best way to manipulate files?
>
>Specifically, I'm trying to do renames and moves and things like that, and
>often times, rename() fails for some reason or another (I'm probably
>feeding it the wrong variables, but OTOH I was reading about some
>limitations of rename()) and I hate to do a system("/bin/mv ...") call,
>for numerous reason.
>
>Is there some great perl module that will help?
If you have a recent perl then you should have the File::Copy module:
NAME
File::Copy - Copy files or filehandles
SYNOPSIS
use File::Copy;
copy("file1","file2");
copy("Copy.pm",\*STDOUT);'
move("/dev1/fileA","/dev2/fileB");
use POSIX;
use File::Copy cp;
$n=FileHandle->new("/dev/null","r");
cp($n,"x");'
[etc.]
Hope this helps,
Mike
--
mike@stok.co.uk | The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/ | PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/ | 65 F3 3F 1D 27 22 B7 41
stok@colltech.com | Collective Technologies (work)
------------------------------
Date: 24 Nov 1997 12:52:11 -0600
From: Kent Perrier <kperrier@Starbase.NeoSoft.COM>
Subject: Re: New to perl. What's wrong with this script?
Message-Id: <cshg925dlw.fsf@Starbase.NeoSoft.COM>
Jeremy Zifchock <jz32@cornell.edu> writes:
> I am trying to have a page that can give directions to events in my area
> that can be updated by another page. here's my script, but it doesn't
> work. Can anyone help? Thanks in advance
> _______________________________________________________________________
Hum, you are not using CGI.pm?
Kent
--
Kent Perrier kperrier@neosoft.com
Corporations don't have opinions, people do. These are mine.
------------------------------
Date: Mon, 24 Nov 1997 05:25:36 GMT
From: jzawodn@wcnet.org (Jeremy D. Zawodny)
Subject: Re: nt build of perl5.004_04
Message-Id: <347c0fb9.192080717@woody.wcnet.org>
[original author automagically cc'd via e-mail]
On 23 Nov 1997 20:18:49 -0800, danny@lennon.postino.com (Danny Aldham)
wrote:
>Thomas Lockney (tlockney@tivoli.com) wrote:
>: Ok, supposedly perl5.004_04 should build on an nt box with cygnus' gnu
>: utilities, right?
>
>Perl builds fine with Microsoft's Visual C++ 5. Use that if you can.
>If you use Cygnus's kit, there are patches to be applied, but first
>you must patch the patch program. No kidding.
Unless you're looking for fork() support, which a lot of folks who
seek the cygnus route are.
Jeremy
--
Jeremy D. Zawodny jzawodn@wcnet.org
Web Server Administrator www@wcnet.org
Wood County Free Net (Ohio) http://www.wcnet.org/
------------------------------
Date: Tue, 25 Nov 1997 00:25:30 +1100
From: Coke <coke@mindless.com>
Subject: ntperl newbie
Message-Id: <3479804A.C9AD04AA@mindless.com>
howdy, i'm new to perl, and am using ntperl 5.001, how do i get
information from forms? the methods i have seen used by unix perl
scripts dont appear to work.
thankyou
------------------------------
Date: 24 Nov 1997 10:38:41 GMT
From: "James Richardson" <jamesr@aethos.co.uk.nospam>
Subject: Re: Perl script making CPU idle time 0.
Message-Id: <01bcf8c5$410abdc0$26c0a4c1@kitkat.aethos.co.uk>
Yogesh Sosale Gundurao <yogesh@ncs.com.sg> wrote in article
<347641D8.A537D945@ncs.com.sg>...
> Hi,
[snip]
>
> Any tips on how to minimize the execution time and reduce cpu usage.
>
You can try 'nice'. Note that this probably wont reduce the CPU
utilisation, but it will mean that other processes have higher priority, so
wont slow down as much.
'shelling out' can cause excessive system load under certain conditions,
especially if your system is memory bound (simple check (not infallible
tho'): use vmstat 5 . Check the value under 'sr', if its large for more
than a couple of lines, you are (probably) very short of memory.) This
problem will be more noticable if your perl process is large (fork() copies
your program space before exec() copies over it) (Maybe perl does vfork(),
which will be better, I dont know).
James Richardson
------------------------------
Date: 24 Nov 1997 06:31:51 GMT
From: yevgene@xochi.tezcat.com (E.None Archibald)
Subject: Re: piping output of multiple files
Message-Id: <65b70o$es9$1@tepe.tezcat.com>
mmoores@digitech.net wrote:
: i have a program which pipes input from tail:
: open F1, 'tail -f alertlog|' or die 'cannot tail';
: while (<F1>) {
: # do some filtering and send email, etc
: }
: this program blocks, and will just sit there..
: i would like to tail on several 'alert log' files
: with one perl script.
Going with the simplest answer - the case where you have something like
the following:
open F1, 'tail -f alertlog|' or die;
open F2, 'tail -f otherlog|' or die;
You want to use select() within a loop. I won't go too deeply into
the select() call here...RTFM, YMMV.
<snippage occurs>
: also, when i parse a line of input i pass it through
: a regular expression like:
: if (/^ORA\-/ or /Warning|Error/) then {#handle stuff here}
: how can i use indirection to get the filter expressions
: from a file and dynamically change them without stopping
: the program?
'ware the linewrap, but the following URL is pretty bang-on to what
you're after (with some adaptation to fit your particular algorithm):
http://www.perl.com/CPAN-local/doc/FAQs/FAQ/PerlFAQ.html#How_do_I_eficiently_match_many_
You may want to install signal handlers (reload the config on a SIGHUP, or
something like it.) There is fairly copius doc around pertaining to this.
--eugene
------------------------------
Date: 24 Nov 1997 11:46:44 GMT
From: eedalf@eed.ericsson.se (Alexander Farber)
Subject: print (...) interpreted as function
Message-Id: <65bpf4$6dc4@aken.eed.ericsson.se>
Hi,
when i am using the -w switch, i become the warning
"print (...) interpreted as function" at the following line:
print ('<A HREF="', path_info () . $ref . '.' . $logfile, '">', $logfile, '</A>')
unless ($logfile eq '-');
Isnt this strange? Isnt print a function? And i also would be
grateful, if someone could explain me, why do i get the warning
"Use of uninitialized value" at the lines:
use CGI qw (:standard :html3);
$upload_dir = '/www/doc' . path_info ();
Thank you for your help!
Alex
------------------------------
Date: 25 Nov 1997 09:56:39 +0100
From: Calle Dybedahl <qdtcall@esb.ericsson.se>
Subject: Re: simple pipe question
Message-Id: <iszpmte4hk.fsf@godzilla.kiere.ericsson.se>
Joel Bremson <staffjb@wenet.net> writes:
> How can I do this?
Probably by telling write() to write to your mail filehandle instead
of STDOUT.
--
Calle Dybedahl, UNIX Sysadmin
qdtcall@esavionics.se http://www.lysator.liu.se/~calle/
------------------------------
Date: 24 Nov 1997 15:47:01 GMT
From: gbacon@adtran.com (Greg Bacon)
To: "Michael R. Harper" <mikihasa@worldnet.att.net>
Subject: Re: sum in assoc array
Message-Id: <65c7hl$3rb$1@info.uah.edu>
[Posted and mailed]
In article <65bidm$cfg@bgtnsc03.worldnet.att.net>,
"Michael R. Harper" <mikihasa@worldnet.att.net> writes:
: foreach $key (keys(%SUM)) {
: ($RESULT{'R'},
: $RESULT{'I'},
: $RESULT{'A'},
: $RESULT{'S'},
: $RESULT{'E'},
: $RESULT{'C'}) += split(" ", $SUM{$key});
: }
Hmmm.. it's not clear what you're trying to do here. (Do you come from
a functional background, by any chance? :-)
: %SUM contains one string: "2 2 2 2 2 2"
Not sure what you mean here, but I suspect you don't have a firm grasp
of what a hash is. Read the perldata manpage.
: It will eventually contain more entries, which I want to sum up and
: store in each of the RESULTS elements.
One way to map the sum of the corresponding value of each key in %SUM
to the value of the same key in %RESULT (e.g. if $SUM{A} is "1 2 3",
then $RESULT{A} will be 6) is
foreach $key (keys %SUM) {
my $sum = 0;
foreach my $i (split ' ', $SUM{$key}) {
$sum += $i;
}
$RESULT{$key} += $sum;
}
TMTOWTDI..
while (($k, $_) = each %SUM) {
## :-) :-) :-)
eval "\$RESULT{'$k'} += (" . join '+', split . ");";
}
or maybe even
while (($k, $_) = each %SUM) {
$RESULT{$k} += map { (1) x $_ } split;
}
but that only works for integers. :-(
If this isn't the problem you're trying to solve (and you can't figure
it out yourself after reading the perldata (and probably perlfunc and
perlsyn) manpages), please repost to the newsgroup with a clearer
explanation of your problem.
Hope this helps,
Greg
--
open(G,"|gzip -dc");$_=<<EOF;s/[0-9a-f]+/print G pack("h*",$&)/eg
f1b88000b620f22320303fa2d2e21584ccbcf29c84d2258084
d2ac158c84c4ece4d22d1000118a8d5491000000
EOF
------------------------------
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 1367
**************************************