[13601] in Perl-Users-Digest
Perl-Users Digest, Issue: 1011 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 7 09:05:25 1999
Date: Thu, 7 Oct 1999 06:05:13 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <939301512-v9-i1011@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 7 Oct 1999 Volume: 9 Number: 1011
Today's topics:
Re: (?p{}) was [Re: Backreference in Regex Code Block?] <kbandes@home.com>
Re: <<EOL and Sub (M.J.T. Guy)
Re: Bug with localtime() in Perl 5.004 and 5.005 (M.J.T. Guy)
Caliing method by reference with arrow operator (Anno Siegel)
Re: Caliing method by reference with arrow operator (Abigail)
Re: Checking for processes (Clinton Pierce)
Re: checking for string in multiple line scalar (part I (M.J.T. Guy)
Re: Command line script vs modules/subroutines (M.J.T. Guy)
Re: Counter (Rainer Jung)
Re: Das GlasPerlenspiel (Stijn van Dongen)
Re: Das GlasPerlenspiel (Anno Siegel)
Re: fork, reap, sig{CHLD} <ak@dasburo.de>
great Larry quote <tzadikv@my-deja.com>
Hash size limit ? (longish) <csaba.raduly@sophos.com>
How to secure PERL-Scripts <schuldt@balticom.de>
Re: inserting new character (Abigail)
Re: inserting new character <r42317@email.sps.mot.com>
Re: inserting new character (Martien Verbruggen)
Looking for a perl version?? (Alexandre Amelin)
mod perl, SSI and DBI problem <jim@bob.com>
Net::IRC -- ? how to use addfh() picklewi@my-deja.com
non blocking joins of Threads? <ak@dasburo.de>
Perl + Java <xxx@xxx.x>
Re: Perl macros for vi (Martien Verbruggen)
Re: Pop-Up reminder <mwilliams@europarl.eu.int>
Re: Question about alarm and run away processes (M.J.T. Guy)
reading binary data files fheitka@attglobal.net
Re: reading binary data files (Martien Verbruggen)
Re: Redirecting output to /dev/null (Clinton Pierce)
search a data base file lowdogg@my-deja.com
Re: Security Query - remote_user <flavell@mail.cern.ch>
Re: tool to convert BMPs to GIFs programatically? (Abigail)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 07 Oct 1999 11:33:18 GMT
From: Kenneth Bandes <kbandes@home.com>
Subject: Re: (?p{}) was [Re: Backreference in Regex Code Block?]
Message-Id: <37FC8537.2FA14AD3@home.com>
lt lindley wrote:
>
> Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
> :>[A complimentary Cc of this posting was sent to lt lindley
> :><lee.lindley@bigfoot.com>],
> :>who wrote in article <7th182$gac$1@rguxd.viasystems.com>:
> :>> This looks like a recursion that continues as long as $foo continues
> :>> to match. But $foo has to stop matching at some point. Why make the
> :>> fact that $foo must fail eventually cause the entire re to return
> :>> false? Make it DWIM.
$foo doesn't have to fail. It just has to stop recursing. That's
why you have the | in it. The non-recursive case succeeds but
still stops the recursion.
Ken Bandes
------------------------------
Date: 7 Oct 1999 11:39:49 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: <<EOL and Sub
Message-Id: <7ti0q5$r0s$1@pegasus.csx.cam.ac.uk>
Charles DeRykus <ced@bcstec.ca.boeing.com> wrote:
>In article <004aa0e3.e569f612@usw-ex0102-016.remarq.com>,
>Samay <samay1NOsaSPAM@hotmail.com.invalid> wrote:
>>Hi, Is there anyway, I can do something like
>>$a = <<EOL
>>the result of sub is
>>&mysub
>>EOL
>>
>>sub mysub{
>> return 5;
>>}
>>
>
>perldoc perlfaq4 | grep "expand function calls"
The FAQ doesn't mention it, but printf / printf is often a useful
alternative:
$a = sprintf <<EOL, mysub();
the result of sub is
%s
EOL
Mike Guy
------------------------------
Date: 7 Oct 1999 12:46:01 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Bug with localtime() in Perl 5.004 and 5.005
Message-Id: <7ti4m9$1bk$1@pegasus.csx.cam.ac.uk>
Larry Rosler <lr@hpl.hp.com> wrote:
>In article <TDqK3.17199$t%3.1261029@typ11.nn.bcandid.com> on Tue, 05 Oct
>1999 17:33:39 GMT, Alan Curry <pacman@defiant.cqc.com> says...
>
>> Currently it says they come from struct tm. And localtime(3) says the tm_sec
>> field of a struct tm goes from 0 to 61. So with the present state of the
>> docs, I'd say that there _are_ leap seconds in perl.
>
>No, there aren't. Or even in Perl. With the present state of the docs,
>I'd say that there _are_ incorrect docs in C (in fact, in the C
>Standard). Which should probably be reported elsewhere.
Actually, you're being unfair to C here. C is careful not to define
what a time_t value (the thing returned by time() ) actually is.
It just has to encode times in some way. And localtime() has
to correctly convert these platform-dependent encodings to the defined
values in a struct tm.
So if your platform uses a time_t which happens to have an encoding for
times which are leap seconds (which the UNIX -- and the Perl --
seconds-since-the-Epoch[*] does not), localtime() will return a value of
60 in the tm_sec field.
And even on a UNIX system, if you get a struct tm value from some
source other than localtime() or gmtime(), say from your friendly
neighbourhood astronomer, then it may well have tm_sec == 60.
Of course, the upper limit of 61 rather than 60 *is* an error, unless
the writers of the C standard were planning for the time system of some
alternative universe.
[*] and note that seconds-since-the-Epoch is a technical term defined
by POSIX, and has a meaning defined by a formula *not* including
leap seconds, rather than the normal English meaning of the phrase.
Mike Guy
------------------------------
Date: 7 Oct 1999 10:59:31 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Caliing method by reference with arrow operator
Message-Id: <7thuej$e65$1@lublin.zrz.tu-berlin.de>
Samuel Kilchenmann <skilchen@swissonline.ch> wrote in comp.lang.perl.misc:
>Abigail <abigail@delanet.com> schrieb in im Newsbeitrag:
>slrn7vn6af.23p.abigail@alexandra.delanet.com...
>> Igor V. Solodovnikov (siv@helpco.kiev.ua) wrote on MMCCXXVII September
>> MCMXCIII in <URL:news:939208052.322601@Stalker.Alfacom.net>:
>> ``
>> `` Is it possible to call method if i have only a reference to it?
>>
>> If you read the documentation carefully, you know you cannot have
>> a reference to a method. What you have is a reference to the
>> subroutine in appropriate class. Slight, but essential difference.
>
>Why? "subroutine in appropriate class" sounds very much like a
>definition of "method".
The way I see it, there is no such thing as a method per se. A sub
is a method when it is intended to be called in a certain way. This
way of calling includes runtime lookup, so if you already have a
coderef, it's too late to call the thing as a method.
>> `` Do you know any workaround?
>>
>> RTFM. Use a closure.
>>
>As far as i understand every reference to a sub or method is a closure
>(although sometimes nothing may be "closed").
>So he already uses a closure.
I don't think so. You get a closure when you compile a subref in
a certain environment, freezing the lexicals that are in scope at
the time. Just saying sub a {...}; $ra = \&a; doesn't make $ra a
closure.
Anno
------------------------------
Date: 7 Oct 1999 04:57:50 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Caliing method by reference with arrow operator
Message-Id: <slrn7vos6r.81.abigail@alexandra.delanet.com>
Samuel Kilchenmann (skilchen@swissonline.ch) wrote on MMCCXXVIII
September MCMXCIII in <URL:news:vKWK3.22737$m4.83746904@news.magma.ca>:
~~ Abigail <abigail@delanet.com> schrieb in im Newsbeitrag:
~~ slrn7vn6af.23p.abigail@alexandra.delanet.com...
~~ > Igor V. Solodovnikov (siv@helpco.kiev.ua) wrote on MMCCXXVII September
~~ > MCMXCIII in <URL:news:939208052.322601@Stalker.Alfacom.net>:
~~ > ``
~~ > `` Is it possible to call method if i have only a reference to it?
~~ >
~~ > If you read the documentation carefully, you know you cannot have
~~ > a reference to a method. What you have is a reference to the
~~ > subroutine in appropriate class. Slight, but essential difference.
~~
~~ Why? "subroutine in appropriate class" sounds very much like a
~~ definition of "method".
But it doesn't do inheritance.
Abigail
--
perl5.004 -wMMath::BigInt -e'$^V=Math::BigInt->new(qq]$^F$^W783$[$%9889$^F47]
.qq]$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W]
.qq]98$^F76777$=56]);$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V
%$^U;$^V/=$^U}while$^V!=$^W'
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Wed, 06 Oct 1999 15:52:02 GMT
From: cpierce1@ford.com (Clinton Pierce)
Subject: Re: Checking for processes
Message-Id: <37fc7003.83338143@news.ford.com>
On Wed, 06 Oct 1999 14:49:07 GMT, mazachan@yahoo.com wrote:
>Hi, I am fairly new to perl and I was wondering, is there a way to
>continuously check for processes that are running without making a
>system call to "ps" and just putting it into a loop? I am looking for a
>more efficient way of doing this. Thanks.
If you have the process' PID, you can use kill() with a zero signal to see
if it's alive.
--
Clinton A. Pierce "If you rush a Miracle Man, you get rotten
clintp@geeksalad.org Miracles." -- Miracle Max, The Princess Bride
http://www.geeksalad.org
------------------------------
Date: 7 Oct 1999 12:09:28 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: checking for string in multiple line scalar (part II)
Message-Id: <7ti2ho$sgg$1@pegasus.csx.cam.ac.uk>
In article <crism-0610991247520001@pm3b-17.meer.net>,
Christopher R. Maden <crism@exemplary.net> wrote:
>In article <7tfjs8$5us$1@tasmania.dev.ict.nl>, "Fokko Wesselius"
><fokko.wesselius@ict.nl> wrote:
>> if ($version_label =~ /(^"ICT.*)/) { print "$1\n"; }
>
>You're only checking for '"ICT' at the beginning of the scalar, not at the
>beginning of each line (this isn't sed). What you probably want to do is
>split $version_label into an array, and then test each member.
Or alternatively, use the /m modifier, and make that into a loop to
find all occurrences:
while ($version_label =~ /(^"ICT.*)/mg) { print "$1\n"; }
Mike Guy
------------------------------
Date: 7 Oct 1999 09:58:30 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Command line script vs modules/subroutines
Message-Id: <7thqs6$lqi$1@pegasus.csx.cam.ac.uk>
Ric Hotchkiss <Ric.Hotchkiss@sdrc.com> wrote:
>
>The main question I have about perl: is there a way to create a script that can
>be used on the command line and also used in another perl script (without
>invoking another perl process (i.e. system or ``)), or will I have to create
>the utilities as modules and write wrapper scripts for command line use?
Well, you *can* have things which are both a script and a module.
It's usually regarded as a bit jokey, but perfectly straightforward.
Look in the standard Perl distribution for an example of how it can be done.
The 'diagnostics.pm' module is the same as the 'splain' script.
Mike Guy
------------------------------
Date: 7 Oct 1999 11:59:51 GMT
From: rj@dungeon.inka.de (Rainer Jung)
Subject: Re: Counter
Message-Id: <slrn7vp2po.8n.rj@coyo.dungeon.inka.de>
+--[ Frank de Bot ]---[ debot@xs4all.nl ]
| Maybe if you write your messages in English we could all understand.
That's the problem, when someone posts in a german and an international
Newsgroup, ..
Rainer
--
Rainer Jung | Beware of Programmers who carry
jura0011@fh-karlsruhe.de | screwdrivers.
------------------------------
Date: Thu, 7 Oct 1999 09:38:13 GMT
From: stijnvd@cwi.nl (Stijn van Dongen)
Subject: Re: Das GlasPerlenspiel
Message-Id: <stijnvd.939289093@news.cwi.nl>
David Cassell <cassell@mail.cor.epa.gov> writes:
>Fujitsu Australia Limited wrote:
>>
>> Is Perl the Glass Bead Game or is the Glass Bead Game available as a Perl
>> module?
>>
>> These rules, the sign language and grammar of the Game, constitute a kind of
>> highly developed secret language drawing upon several science and arts, but
>> especially mathematics and music, and capable of expressing and establishing
>> interrelationships between the contents and the conclusions of nearly all
>> scholarly disciplines, The Glass Bead Game is thus a mode of playing with
>> the total contents and values of our culture; it plays with them as, say, in
>> the great age of the arts painter might have played with the colors of his
>> palette. All the insights, noble thoughts, and works of art that the human
>> race has produced in its creative eras, all that subsequent periods of
>> scholarly study have reduced to concepts and converted to intellectual
>> property - on all this immense body of intellectual values the Glass Bead
>> Game player plays like an organist on the organ.
>>
>> Hermann Hesse
>> Das Glasperlenspiel
>> 1943
>Clearly, this is not Perl, but Mystery Science Theater 3000.
I liked this intermezzo. It befits the eclectical origins of Perl.
It's nice to put things in a poetic perspective once every while.
It's something that Larry Wall does in his lectures too, if I
may say so, and no, I am not comparing the two.
It's been a long time since I read 'Das Glasperlenspiel'
and this post, making an unexpected link, got me smiling.
Regards,
Stijn
--
Stijn van Dongen
Centrum voor Wiskunde en Informatica (CWI)
Kruislaan 413 1098 SJ Amsterdam @ _ @
tel: +31 20 5924180 stijnvd@cwi.nl <_`'/_/ _>
------------------------------
Date: 7 Oct 1999 12:04:18 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Das GlasPerlenspiel
Message-Id: <7ti282$ebj$1@lublin.zrz.tu-berlin.de>
Fujitsu Australia Limited <andrew.yuen@fujitsu.com.au> wrote in comp.lang.perl.misc:
>bowman wrote in message
>>Despite being fairly proficient in a couple of OO
>>languages, I'm having some trouble figuring out how to bless my
>>thingies. Need a session with the Magister Ludi.
>
>There's a great article in The Perl Journal issue 14 - Building a Better
>Hash, by Dan Schmidt. It introduces the whole blessed thing:
>
>http://www.itknowledge.com/tpj/issues/vol4_2/ewtoc.html
>
>You have to subscribe to get access, but it's well worth it. The Camel Book
>has a decent section on objects. The Perl approach is very different. For
>example- it just asks people to be considerate and follow the rules when
>using modules, rather than having systems in place to prevent access to
>private data.
Yes. An earlier version of the camel put it somewhat like this: Perl
expects you to stay out of the living room because you weren't invited,
not because it has a shotgun.
The trouble is, it doesn't even tell you where the friggin living room
*is*. So, unless you have some experience with the oo approach, or
modularization, or whatever, you stumble around... When you happen
into the living room, you find out that Perl does have a shotgun.
Anno
------------------------------
Date: Thu, 07 Oct 1999 14:55:21 +0200
From: Alexander Knack <ak@dasburo.de>
To: frank_c4568@my-deja.com
Subject: Re: fork, reap, sig{CHLD}
Message-Id: <37FC9839.E7D2D4A1@dasburo.de>
$SIG{CHLD} = \&checker;
if (fork == 0) {
print "halllo\n";
exit 12;
}
sleep 10;
sub checker {
my ($pid) = wait();
my $res = $?;
$res = $res >> 8;
print "$pid returned $res\n";
}
--
+--------------------------------------------------------------------+
| Alexander Knack ........Entropie erfordert keine Wartung .........|
| dasburo.de ..................................................|
+--------------------------------------------------------------------+
------------------------------
Date: Thu, 07 Oct 1999 12:51:14 GMT
From: Tzadik Vanderhoof <tzadikv@my-deja.com>
Subject: great Larry quote
Message-Id: <7ti4vt$jrf$1@nnrp1.deja.com>
I hapenned on a great quote in a post from Larry in a '94 archive of
the "comp.lang.perl" (I haven't seen this quote in any of the "quote
collections"... my apoligies if you've seen it before) :
I do worry about syntactic clutter, ever since my daughter came
in, looked over my shoulder, and said, "What is that, swearing?"
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 07 Oct 1999 12:53:49 +0100
From: Csaba Raduly <csaba.raduly@sophos.com>
Subject: Hash size limit ? (longish)
Message-Id: <37FC89CD.1EE19540@sophos.com>
I've written a log file analyser used to test our new virus engine.
Basically it checks that the right viruses are found in the various
test files. The log files look like this:
(first character is a \t : )
M:\path...\filename
>>> Virus 'Melissa' found in M:\path...\filename
There's an HTML document describing which files contain which viruses.
Another perl script parses it and produces perl include files
with the following format:
----cut here-------------chapter32.exp----------
%expected = (
'file1', 'virus1',
'file2', 'virus2',
);
----cut here-------------chapter32.exp-end------
The basename of the file is the same as the log file for the
corresponding chapter (i.e. chapter23.log and chapter32.exp)
The correct exp file is included via do $expfile
(it used to be require, if you remember my previous post
about "How to undo a require")
During processing the filename is isolated and then used
as a key into the hash, and the value (expected virus)
is checked against the actual virus detected.
Yesterday I decided that it's time to do things on a grand scale
and took the log file generated by the "official" version run
over the entire virus collection, and passed it through
yet another perl script to generate a big exp file
(and I mean big: it's over 3M in size)
But when I try to include the big one using do,
the hash appears to be empty.
( foreach $key (keys %expected){ print $key } does nothing )
No error message is generated.
I started to chop it down to see where it stops working.
Apparently the limit is around 1761 lines or a file of 93500 bytes.
I suspect the problem isn't some limit in the hash size;
rather an input buffer size limit (?)
I'm using perl 5.0 patchlevel 5 subversion 53 on OS/2
Any ideas what's up ?
Csaba
--
-----BEGIN GEEK CODE BLOCK-----
Version 3.1
GCS/>GMU d- s:- a30 C++$ UL+ P+>+++ L++ E- W+ N++ o? K? w++>$ O++$ M-
V- PS PE Y PGP- t+ 5 X++ R* tv++ b++ DI+++ D++ G- e+++ h-- r-- !y+
-----END GEEK CODE BLOCK-----
Csaba Raduly, Software Developer (OS/2), Sophos Anti-Virus
mailto:csaba.raduly@sophos.com http://www.sophos.com/
US Support +1 888 SOPHOS 9 UK Support +44 1235 559933
Life is complex, with real and imaginary parts.
------------------------------
Date: Thu, 07 Oct 1999 11:40:26 +0200
From: Norbert Schuldt <schuldt@balticom.de>
Subject: How to secure PERL-Scripts
Message-Id: <37FC6A8A.CF93358B@balticom.de>
Hi Folks,
I've installed certain domains (customers) on my IIS. The homedirs are
all
located on one physical drive. All customers use their own cgi-bin dir.
ActivePerl is installed.
Now there might be one problem : Using the system() command in PERL one
customer can easily get the other one's information (files) or even
"damage" the
server. Is there any possibility to give a cgi-bin access to the
customers
which is "secure" ??
Please also reply by mail
TIA
Norbert
------------------------------
Date: 7 Oct 1999 05:03:54 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: inserting new character
Message-Id: <slrn7vosi7.81.abigail@alexandra.delanet.com>
Noira Hadi (r42317@email.sps.mot.com) wrote on MMCCXXVIII September
MCMXCIII in <URL:news:37FC43AD.28DA9B3E@email.sps.mot.com>:
&& Thanks for your posting, Abigail. I appeciate that. I got result as below whe
&& running your script:
If you Cc me, please write that in the email. Or don't Cc me.
And don't post lines over 80 chars. Keep it to 75 or less.
&& It seems that your script is always adding C before D and prints the data whe
&& reached D.
Well, yes. All you give was an example, no specification of your problem.
People, if you have a problem you want to have solved, the least thing
you can do is define the problem accurately. Noone is going to smell
the specification from an *example*.
&& My problem is that I have a variable data set for 'B' (say, up to maximum of
&& data). I want to process them and allocate 10 columns for 'B'. But, when the
&& data is less than 10, I will add 'C' to substitute the column allocated for '
&& other words, can I have something like:
&&
&& A,B,B,B,B,B,B,B,B,B,B,D
&& A,B,B,C,C,C,C,C,C,C,C,D
&& A,B,B,B,B,C,C,C,C,C,C,D
&& A,B,C,C,C,C,C,C,C,C,C,D
&&
&& I know I will have to use loop but haven't been able to get it right.
Well, what *do* you have? Are we having to guess your code?
&& Thanks and Regards,
&& hadi
&&
&& Abigail wrote:
Urg. Stealth Cc, lines over 80 chars, Jeopardy style posting,
quoting of sig. poorly defined problem, and no code.
Why do I even bother?
*plonk*
Abigail
--
perl -e '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %;
BEGIN {% % = ($ _ = " " => print "Just Another Perl Hacker\n")}'
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Thu, 07 Oct 1999 18:50:19 +0800
From: Noira Hadi <r42317@email.sps.mot.com>
Subject: Re: inserting new character
Message-Id: <37FC7AEB.47B31D4D@email.sps.mot.com>
Abigail,
This is the script that I have:
#!/usr/local/bin/perl -w
open(INF,"dat") ;
@ary = <INF>;
close(INF);
for ($loop=1; $loop<2; $loop++) {
foreach $line (@ary) {
if ($line =~ /A/){
chomp($line);
print "$line,";
}
elsif ($line =~ /B/) {
chomp($line);
print "$line,";
}
elsif ($line =~ /D/) {
chomp($line);
print "$line \n";
}
}
}
The data I'm processing is below:
filename: dat
A
B
B
B
B
B
B
B
B
B
B
D
A
B
B
B
B
D
A
B
B
D
I just want to know how to put C in place so that I'll get the result as below:
A,B,B,B,B,B,B,B,B,B,B,D
A,B,B,B,B,C,C,C,C,C,C,D
A,B,B,C,C,C,C,C,C,C,C,D
Thanks,
hadi
------------------------------
Date: 7 Oct 1999 11:30:05 GMT
From: mgjv@wobbie.heliotrope.home (Martien Verbruggen)
Subject: Re: inserting new character
Message-Id: <slrn7vp03u.57o.mgjv@wobbie.heliotrope.home>
On Thu, 07 Oct 1999 18:50:19 +0800,
Noira Hadi <r42317@email.sps.mot.com> wrote:
> Abigail,
>
> This is the script that I have:
>
> #!/usr/local/bin/perl -w
-w, that's good. It would be better if you were also using the strict
pragma. It'll save you a lot of debugging grief.
> open(INF,"dat") ;
you should always check the return code of a system call. open() is
one.
open(INF, 'dat') or die "Cannot open dat for reading: $!";
> for ($loop=1; $loop<2; $loop++) {
Why this loop? You only loop once.
I will take this bit to mean that a single D on a line ends the input
series, right?
[snip code and data]
[reformat of line that's too long]
> I just want to know how to put C in place so that I'll get the
> result as below:
>
> A,B,B,B,B,B,B,B,B,B,B,D
> A,B,B,B,B,C,C,C,C,C,C,D
> A,B,B,C,C,C,C,C,C,C,C,D
Ok.. let me try to interpret that. You want to 'fill' the space
between the B and the D with C's, so that each subsequent series
becomes just as long as the first one. If not, you'll have to
calculate the fill number another way than I will be doing.
I would probably do something like this:
#!/usr/bin/perl -w
use strict;
my $length;
my @buf;
while (<DATA>)
{
chomp;
if ($_ eq 'D')
{
# End of series
# set the length, if it isn't already set
$length = @buf unless defined $length;
# add some C's until we have enough
push @buf, 'C' while(@buf < $length);
# Don't forget to add the current terminator
push @buf, $_;
print join(',', @buf), "\n";
# And reset the buffer
@buf = ();
}
else
{
# Add anything that isn't a 'D' to the end of the buffer
push @buf, $_;
}
}
__DATA__
A
B
B
B
B
B
B
B
B
B
B
D
A
B
B
B
B
D
A
B
B
D
OUTPUT:
A,B,B,B,B,B,B,B,B,B,B,D
A,B,B,B,B,C,C,C,C,C,C,D
A,B,B,C,C,C,C,C,C,C,C,D
Of course there are many other ways of doing this, and many small
variations on the same way of doing this. This won't get a high perl
golf score, but then, you probably wouldn't learn as much if it did :)
Martien
--
Never do too much when programming. It's a waste of time and CPU, it
makes you lose the plot, and your keyboard wears out faster.
------------------------------
Date: Thu, 07 Oct 1999 14:23:06 +0200
From: aamelin@mmm.com (Alexandre Amelin)
Subject: Looking for a perl version??
Message-Id: <37FC90AA.893E62BE@mmm.com>
I'm looking for a hold version of perl for Windows :
Version 4.0.1.8 Build 3 Patch level 36.
(I need to use it for Tivoli integrations)
Some body knows where I can find it.
Please help me!!!
Hal.
Opinions expressed herein are my own and may not represent those of my employer.
------------------------------
Date: Thu, 07 Oct 1999 12:31:37 +0100
From: Thomas Nunn <jim@bob.com>
Subject: mod perl, SSI and DBI problem
Message-Id: <37FC8499.7342D327@bob.com>
I've been attempting to use mod perl to run a script that I've written.
I've got the actual script to work fairly nicely, but I would like to be
able to use Server Side Includes in it so that it will fit in nicely
with the rest of the site I'm working on.
I'm using Suse Linux and Apache before you ask.
Is there anythinbg different about declaring the include if I'm using
mod perl? I had heard that mod perl automatically does includes, but it
isn't working at all. Is there maybe another Apache module that I have
to use?
The script also uses DBI to connect to a MySQL database. I have read
some info on using the Apache::DBI module to open connections to the
database. But after I tried to implement that using 'Perlmodule
Apache::DBI' in the httpd config file my alias /perl-bin/ dissapeared.
In fact any module I attempt to load has the same effect.
What am I doing wrong? If anyone can be of any help I would be very
grateful.
Oh, by the way. I'm not the one who installed Apache and mod perl on the
system here, and I'm faily confused about the way it's set up, it
wouldn't surprise me if one of you told me that was the problem.
Thanks....
Tom Nunn.
Please reply to the group, the reply email is not my actual address.
------------------------------
Date: Thu, 07 Oct 1999 12:26:24 GMT
From: picklewi@my-deja.com
Subject: Net::IRC -- ? how to use addfh()
Message-Id: <7ti3h4$iul$1@nnrp1.deja.com>
Cab somebody send me (william.pickles@wdr.com) some sample code to call
addfh() so I can convert the sample 'bot irctest from a synchronous
(using $self->start() ) to an asynchronous form ( $self->do_one_loop() )
In particular I want to leave the standard call backs in place
William
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 07 Oct 1999 14:31:00 +0200
From: Alexander Knack <ak@dasburo.de>
Subject: non blocking joins of Threads?
Message-Id: <37FC9284.B8C62FC5@dasburo.de>
hi,
suppose the following code:
use strict;
use Thread;
my $var1;
my $var2;
my $var3;
my @threads;
$threads[0] = new Thread \&sub1;
$threads[1] = new Thread \&sub2;
$threads[2] = new Thread \&sub3;
map { $_->join() } (@threads);
print "$var1; $var2; $var3\n";
sub sub1{
$var1 = "inhalt1";
}
sub sub2{
$var2 = "inhalt2";
}
sub sub3{
$var3 = "inhalt3";
}
the documentation says that join waits blocking.
how may one modify the code above, so that the join is nonblocking.
something like
while (! all threads finished) {
if (thread id N finished) { do this } else { do that }
}
--
+--------------------------------------------------------------------+
| Alexander Knack ........Entropie erfordert keine Wartung .........|
| dasburo.de ..................................................|
+--------------------------------------------------------------------+
------------------------------
Date: Thu, 7 Oct 1999 12:41:11 +0200
From: "xxx" <xxx@xxx.x>
Subject: Perl + Java
Message-Id: <37fc7831.0@noticias.ncsa.es>
I know that I can call a C programm from a cgi written in perl and I would
like to know if it's also possible to call a java application.
P.S: If not, I would also be very gratefull if you could tell me where can I
find information
about calling C programms from a script in perl.
------------------------------
Date: 7 Oct 1999 10:36:24 GMT
From: mgjv@wobbie.heliotrope.home (Martien Verbruggen)
Subject: Re: Perl macros for vi
Message-Id: <slrn7vosv9.56q.mgjv@wobbie.heliotrope.home>
On 7 Oct 1999 03:40:01 -0500,
Abigail <abigail@delanet.com> wrote:
> Martien Verbruggen (mgjv@wobbie.heliotrope.home) wrote on MMCCXXVII
> September MCMXCIII in <URL:news:slrn7vmf3e.2h3.mgjv@wobbie.heliotrope.home>:
> -- On Wed, 6 Oct 1999 07:59:31 GMT,
> -- I.J. Garlick <ijg@connect.org.uk> wrote:
> --
> -- > Do yourself a favour go get a better background gif.
> --
> -- use lynx, and you won't even see what sort of background he uses :)
>
>
> I don't need to use lynx for that; I won't see it with Netscape either ;-)
Maybe, but you're still suffering :)
--
When in doubt, look around
------------------------------
Date: Thu, 07 Oct 1999 12:44:00 +0200
From: "williams, mark" <mwilliams@europarl.eu.int>
Subject: Re: Pop-Up reminder
Message-Id: <JXn8N7znPNvDOSgWkKZzofxOfg13@4ax.com>
SNIP Tk >>>
Or on a Win32 just do this
$foff_n_die=&warn_and_die("No News proxy for $lsu $site");
}
sub warn_and_die{
Win32::MsgBox("@_[0], \n Please contact LSA", MB_ICONEXCLAMATION,
"NewsStarter");
die;
}
Wilf Williams
MCSE
http://members.tripod.com/williams_mr
The Opinions expessed are my own (I don't have an employer!)
------------------------------
Date: 7 Oct 1999 12:18:47 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Question about alarm and run away processes
Message-Id: <7ti337$t3n$1@pegasus.csx.cam.ac.uk>
In article <rvncbf73n8a49@corp.supernews.com>,
Ilya <ilya@speakeasy.org> wrote:
>
>
>I process a lot of sar data with a perl script. I have seen cases where the
>sar data is incomplete or corrupt and the sar process hangs and begins to
>increase CPU consumption until it hits 99%.
>
>I would like to use the alarm function to check if I am dealing with a
>run-away process and if it is indeed a run-away, kill it.
Start with the FAQ entry, which I found in seconds with
'perldoc -q timeout':
perlfaq8: How do I timeout a slow event?
and then the references therein.
Mike Guy
------------------------------
Date: 7 Oct 1999 11:45:43 GMT
From: fheitka@attglobal.net
Subject: reading binary data files
Message-Id: <37fc87e7_3@news1.prserv.net>
Keywords: binary, data, Perl
I can't find any good examples on how to read binary
data files from disk. I've searched all the good sites
I could find about Perl. Say I had a C structure like:
struct mystruct {
int num;
double data[100];
char *ident="Test 9/21/99 data"
};
and I wrote to disk in a C program using fwrite.
How could I read that same data using a Perl
program.
--
Fred
------------------------------
Date: 7 Oct 1999 12:35:43 GMT
From: mgjv@wobbie.heliotrope.home (Martien Verbruggen)
Subject: Re: reading binary data files
Message-Id: <slrn7vp3uv.57o.mgjv@wobbie.heliotrope.home>
On 7 Oct 1999 11:45:43 GMT,
fheitka@attglobal.net <fheitka@attglobal.net> wrote:
> I can't find any good examples on how to read binary
> data files from disk. I've searched all the good sites
> I could find about Perl. Say I had a C structure like:
Interesting. Just after I proclaim my aversion for pack and unpack, I
keep seeing these threads that need them. And no, I don't _really_
believe the universe revolves around me.
you might already have gathered, you need pack and unpack for these
sorts of binary manipulations.
# perldoc pack
# perldoc unpack
> struct mystruct {
> int num;
> double data[100];
> char *ident="Test 9/21/99 data"
This last one makes it hard. You cannot, in C, write this thing to
disk, and expect that string to me there. What you will have on disk
is the value of the pointer, and that will be meaningless on a read.
I will therefore ignore this field. You can't use it in Perl, and you
can't use it in C. structs like this need specialised read/write
routines.
Besides that, you can't initialise parts of your struct like that.
> };
Ok, just for the heck of it,. let me try to write the correct template
for that.. Forgive the C code, just to show correspondence between the
write and read.
$ cat struct.c
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
struct ms
{
int num;
double data[100];
char *ident;
};
int main(void)
{
struct ms foo;
int i;
FILE *f;
foo.num = 42;
for (i = 0; i < 100; i++)
{
foo.data[i] = (i + 1) * 4 * atan(1.0);
}
foo.ident = "Test 9/21/99 data";
if ((f = fopen("/tmp/foo", "wb")) == NULL)
{
perror("Couldn't open /tmp/foo for write");
return 1;
}
/* yes, I know it's meaningless to write that pointer to disk
* and yes, I know I should check the result of this
*/
fwrite( &foo, sizeof(foo), 1, f);
fclose(f);
return 0;
}
$ cat struct.perl
#!/usr/bin/perl -w
use strict;
# Just get the whole file in a variable in this case
# Could have done this with a stat and read to be more C-ish :)
open(FOO, "/tmp/foo") or die "Cannot open /tmp/foo for read: $!";
binmode(FOO);
undef $/;
my $struct = <FOO>;
close(FOO);
my ($num, @data) = unpack "id100p", $struct;
# Get rid of the useless pointer reference
my $ident = pop @data;
print "$num\n";
print scalar @data, " elements:\n";
foreach (@data)
{
print "\t$_\n";
}
$ gcc -ansi -pedantic -Wall -o struct struct.c -lm
$ ./struct
$ ./struct.perl
42
100 elements:
3.14159265358979
6.28318530717959
9.42477796076938
[snip]
314.159265358979
Martien
PS. To do something useful with the contents of the pointer, you will
not need to know what the struct looks like, but how it is written to
disk. Just as you would with a C program that needs to read it.
--
When in doubt, look around
------------------------------
Date: Wed, 06 Oct 1999 14:21:56 GMT
From: cpierce1@ford.com (Clinton Pierce)
Subject: Re: Redirecting output to /dev/null
Message-Id: <37fb5877.77310887@news.ford.com>
On Wed, 06 Oct 1999 04:04:37 GMT, bounce.waxwing@dnai.com (Scot Hacker)
wrote:
>to dump the output to the bit bucket. So I want to do this from my perl
>script, and I use:
>
>@ControlSP = ("hey", "SoundPlay", "set", "file", "of", "track", \
>"0", "to", "file\($Current\)", ">", "/dev/null");
>system (@ControlSP);
Almost! When system() is passed a list, it doesn't hand the command to
the shell for processing, it just exec's the program "hey" with the right
arguments. The shell gets no chance to do the "/dev/null" redirection
because it's never called.
If you had put that all together as one string, the shell gets to do the
redirection and then run your program:
$ControlSP = "hey SoundPlay set file of track 0 to file\($Current\) >
/dev/null";
system ($ControlSP);
(Not tested, please verify...)
--
Clinton A. Pierce "If you rush a Miracle Man, you get rotten
clintp@geeksalad.org Miracles." -- Miracle Max, The Princess Bride
http://www.geeksalad.org
------------------------------
Date: Thu, 07 Oct 1999 12:40:45 GMT
From: lowdogg@my-deja.com
Subject: search a data base file
Message-Id: <7ti4cb$jeb$1@nnrp1.deja.com>
hey,
I have been strugling for some time to try and
figured out a way to search a flat file database
and if a component in database is already present
not to print it but for some reason it still
prints no matter if the component is present or
not I have tryed the grep function a foreach loops
but none seem to work please help me
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 7 Oct 1999 13:37:55 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Security Query - remote_user
Message-Id: <Pine.HPP.3.95a.991007132142.2759E-100000@hpplus01.cern.ch>
On Thu, 7 Oct 1999, Mario Covino wrote:
> Our Internet/Intranet PERL applications rely heavily on the Environment
> variable "remote_user" which is set by the web server when the user logs
> in.
Right, it's set by the web _server_. And your Perl language question
is?
> question is, can the value of these environment variables be
> changed/hacked at the client end,
All the ones that are set directly from client data, yes. For
example the HTTP_* variables that are set from client HTTP headers.
> specifically the "remote_user". ?
As you already noted, that's set by the _server_ on the basis of the
authentication data. Hence or otherwise deduce that it can only be
hacked by sending authentication data which is false but which is
accepted by the server.
Your security review will show how relevant this possibility is to your
chosen level of risk.
> I have searched the Internet high and wide for proof one
> way or another ,
This kind of statement always worries me. Why "search high and wide"
when there is a published interworking specification to refer to?
> can anyone with authority tel me the answer.
I expect so. How will you recognize one when you see them?
Taking the CGI spec together with the current HTTP RFCs should give you
the authoritative answer.
De facto CGI spec: http://hoohoo.ncsa.uiuc.edu/cgi/interface.html
Internet-Draft CGI spec:
http://web.golux.com/coar/cgi/draft-coar-cgi-v11-03-clean.html
HTTP protocol: RFC2616 and 2617 (at your local friendly repository of
Internet documents)
f'ups set to more appropriate group.
good luck
------------------------------
Date: 7 Oct 1999 04:05:01 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: tool to convert BMPs to GIFs programatically?
Message-Id: <slrn7vop3q.81.abigail@alexandra.delanet.com>
Scott McMahan (scott@aravis.softbase.com) wrote on MMCCXXVI September
MCMXCIII in <URL:news:EDpK3.1178$H32.71815@newshog.newsread.com>:
__
__ But GIFs are patent-protected, or something, and require a license
__ from whoever has the legal rights to them, aren't they? Can you
__ make freeware that supports GIFs without having to pay
__ for the rights to them?
Yes. But you cannot make everything.
Abigail
--
perl -MTime::JulianDay -lwe'@r=reverse(M=>(0)x99=>CM=>(0)x399=>D=>(0)x99=>CD=>(
0)x299=>C=>(0)x9=>XC=>(0)x39=>L=>(0)x9=>XL=>(0)x29=>X=>IX=>0=>0=>0=>V=>IV=>0=>0
=>I=>$r=-2449231+gm_julian_day+time);do{until($r<$#r){$_.=$r[$#r];$r-=$#r}for(;
!$r[--$#r];){}}while$r;$,="\x20";print+$_=>September=>MCMXCIII=>()'
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V9 Issue 1011
**************************************