[23768] in Perl-Users-Digest
Perl-Users Digest, Issue: 5972 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Dec 23 09:05:38 2003
Date: Tue, 23 Dec 2003 06:05:07 -0800 (PST)
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, 23 Dec 2003 Volume: 10 Number: 5972
Today's topics:
Re: ${'Q::' . $var} and use strict <not_a_real@adress.getting.too.much.spam.org>
Accounting, Database Problem <nospam.hciss@yahoo.com>
Re: Accounting, Database Problem (Anno Siegel)
Re: Accounting, Database Problem <nospam@bigpond.com>
Re: Accounting, Database Problem (Tim Shoppa)
Re: Accounting, Database Problem (Sara)
Re: Accounting, Database Problem (Sara)
Re: Add Files to Zip File (Anno Siegel)
Re: fork <mgjv@tradingpost.com.au>
Re: fork <notpublic@restricted.com>
Re: help with file test <matthew.garrish@sympatico.ca>
Re: help with file test <matthew.garrish@sympatico.ca>
Re: Parsing File <me@privacy.net>
Re: Parsing File (Anno Siegel)
PDF creation in Perl <iain@smokehythe.net>
Re: PDF creation in Perl <carsten@welcomes-you.com>
Re: PDF creation in Perl <calle@cyberpomo.com>
Re: Perl DB question (Anno Siegel)
Re: Please critique this short script that scans a log <jwngaa@att.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 22 Dec 2003 22:37:41 -0800
From: "Damian" <not_a_real@adress.getting.too.much.spam.org>
Subject: Re: ${'Q::' . $var} and use strict
Message-Id: <bs8nnu$aaq2e$1@ID-196529.news.uni-berlin.de>
"Jim Keenan" <no_spam_for_jkeen@verizon.net> wrote:
[A helpful post for the OP]
> Also, when posting a question that
> involves CGI to a newsgroup or mailing list, try to isolate the
problem. Is
> it a CGI-problem? If so, post to a CGI newsgroup (see c.l.p.m.
Posting
> Guidelines for suggestions). Is it a Perl question (as I suspect it
is in
> this instance)? If so, then strip out all CGI-related code before you
post.
> You may find that that clarifies your understanding of the code and
> contributes to solving the problem.
I think a post like this, that happens to use CGI.pm, which is *part* of
Perl, should be completely acceptable. The OP didn't ask about CGI, but
a very Perl question.
If it's a question that's about something that wont work CGI or
otherwise related to CGI and not the Perl code it self, then it's much
better off in a CGI newsgroup (C.I.W.A.C).
If it's a Perl question for a script that makes use of CGI.pm, but the
question/problem is in the Perl code itself, then there should be no
problem posting it here.
I'm just saying this because I don't want the OP to get the wrong
impression, that is, that you can't post and code snippet that contains
CGI.pm, which is not the sole criteria.
IMHO, it is usually obvious of the question is a Perl question and not a
CGI question. Like the OP's question.
------------------------------
Date: Tue, 23 Dec 2003 00:53:39 -0600
From: "Matt" <nospam.hciss@yahoo.com>
Subject: Accounting, Database Problem
Message-Id: <vufpika4211r45@corp.supernews.com>
I have a weird need for a database of sorts.
I have 100 too 300 usernames. Every hour I want to add an accounting value
to each user.
1st-hour> user1 1245
2nd-hour changes too > user1 1245,13456
This goes on until the user has 500 values then the oldest value is deleted
to keep it at no more then 500 values at any time. This is sort of a
scrolling window. I also need to add up the values to get a total for each
user every hour as well.
Is approaching this with a text file like this a bad way to go? I like text
files, I understand them. Does perl have any tools to make this easier for
me?
Matt
------------------------------
Date: 23 Dec 2003 10:10:37 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Accounting, Database Problem
Message-Id: <bs94at$g25$1@mamenchi.zrz.TU-Berlin.DE>
Matt <nospam.hciss@yahoo.com> wrote in comp.lang.perl.misc:
> I have a weird need for a database of sorts.
>
> I have 100 too 300 usernames. Every hour I want to add an accounting value
> to each user.
>
> 1st-hour> user1 1245
> 2nd-hour changes too > user1 1245,13456
>
> This goes on until the user has 500 values then the oldest value is deleted
> to keep it at no more then 500 values at any time. This is sort of a
> scrolling window. I also need to add up the values to get a total for each
> user every hour as well.
>
> Is approaching this with a text file like this a bad way to go? I like text
> files, I understand them. Does perl have any tools to make this easier for
> me?
There is no Perl content in your question.
Whether your technique is reasonable or not depends on the way the
updates happen. If you have new values for all 300 users once an hour,
updating the file should be no problem. If the data comes individually
for every user, that would amount to five updates per minute. That
won't bring a system down, but it may be more than you want to invest
in accounting. This bit of arithmetic isn't exactly rocket science.
Anno
------------------------------
Date: Tue, 23 Dec 2003 21:23:16 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: Accounting, Database Problem
Message-Id: <1767551.cp6isrQgrB@gregs-web-hosting-and-pickle-farming>
It was a dark and stormy night, and Matt managed to scribble:
> I have a weird need for a database of sorts.
>
> I have 100 too 300 usernames. Every hour I want to add an accounting
> value to each user.
>
> 1st-hour> user1 1245
> 2nd-hour changes too > user1 1245,13456
>
> This goes on until the user has 500 values then the oldest value is
> deleted
> to keep it at no more then 500 values at any time. This is sort of a
> scrolling window. I also need to add up the values to get a total for
> each user every hour as well.
>
> Is approaching this with a text file like this a bad way to go? I like
> text
> files, I understand them. Does perl have any tools to make this easier
> for me?
>
> Matt
I'd use a database, since I've a database kinda guy for 20 years.
I'd use two tables, say users & dynamic_info. Just insert, delete data as required.
When you need to do your accounting, have a look at a select statement with 'count(*)' 'sum(*)' and 'group by' and a join on the two tables. There sould be examples of these in your database documentation.
You can do this all with Perl DBI.
gtoomey
------------------------------
Date: 23 Dec 2003 04:57:17 -0800
From: shoppa@trailing-edge.com (Tim Shoppa)
Subject: Re: Accounting, Database Problem
Message-Id: <bec993c8.0312230457.95bd42e@posting.google.com>
"Matt" <nospam.hciss@yahoo.com> wrote in message news:<vufpika4211r45@corp.supernews.com>...
> I have a weird need for a database of sorts.
>
> I have 100 too 300 usernames. Every hour I want to add an accounting value
> to each user.
>
> 1st-hour> user1 1245
> 2nd-hour changes too > user1 1245,13456
>
> This goes on until the user has 500 values then the oldest value is deleted
> to keep it at no more then 500 values at any time. This is sort of a
> scrolling window. I also need to add up the values to get a total for each
> user every hour as well.
>
> Is approaching this with a text file like this a bad way to go? I like text
> files, I understand them. Does perl have any tools to make this easier for
> me?
MRTG is a very common application which uses text files to store "scrolling
windows". See http://www.mrtg.org/ for more of its inner workings.
The MRTG approach is certainly workable, and probably will scale to a few
hundred users without a lot of pain. What is somewhat painful is
the need for lockfiles to prevent one application writing a window-file while
another is shifting it. Or, even worse, two shifters from attempting
to do the same thing at the same time. Perl/CPAN has a lot of tools for
dealing with such lockfiles, so it won't be so bad, but any application
that might want to deal with the data has to deal with the lockfiles correctly.
For more than a few hundred users, it sounds like it may be better handled by
BerkeleyDB::Btree or MySQL with the time as a primary key. These handle
locking and can delete the "old" records with no need for an (open file,
shift the data, write file) sequence.
Tim.
------------------------------
Date: 23 Dec 2003 05:31:19 -0800
From: genericax@hotmail.com (Sara)
Subject: Re: Accounting, Database Problem
Message-Id: <776e0325.0312230531.53591ecb@posting.google.com>
"Matt" <nospam.hciss@yahoo.com> wrote in message news:<vufpika4211r45@corp.supernews.com>...
> I have a weird need for a database of sorts.
>
> I have 100 too 300 usernames. Every hour I want to add an accounting value
> to each user.
>
> 1st-hour> user1 1245
> 2nd-hour changes too > user1 1245,13456
>
> This goes on until the user has 500 values then the oldest value is deleted
> to keep it at no more then 500 values at any time. This is sort of a
> scrolling window. I also need to add up the values to get a total for each
> user every hour as well.
>
> Is approaching this with a text file like this a bad way to go? I like text
> files, I understand them. Does perl have any tools to make this easier for
> me?
>
> Matt
Hi Matt:
Whenever you see an array of <somethings> it should imply an array
struct to you. I find that usually the most obvious storage solution
is the best. Your case suggests an array of array. You can then sort
the array if you need to when using it- I'm not sure about your
application in that respect.
Of course you want the data to persist, so you'll want to "tie" it.
Look in this group or Camel for lots of examples of tie-ing.
Cheers,
G
------------------------------
Date: 23 Dec 2003 05:34:43 -0800
From: genericax@hotmail.com (Sara)
Subject: Re: Accounting, Database Problem
Message-Id: <776e0325.0312230534.18b857ed@posting.google.com>
"Matt" <nospam.hciss@yahoo.com> wrote in message news:<vufpika4211r45@corp.supernews.com>...
> I have a weird need for a database of sorts.
>
> I have 100 too 300 usernames. Every hour I want to add an accounting value
> to each user.
>
> 1st-hour> user1 1245
> 2nd-hour changes too > user1 1245,13456
>
> This goes on until the user has 500 values then the oldest value is deleted
> to keep it at no more then 500 values at any time. This is sort of a
> scrolling window. I also need to add up the values to get a total for each
> user every hour as well.
>
> Is approaching this with a text file like this a bad way to go? I like text
> files, I understand them. Does perl have any tools to make this easier for
> me?
>
> Matt
PS: I forgot- you did say you wanted to limit the array to 500
elements. Thats easy, try someting like:
push @a, $newvalue;
shift @a if @x > 500;
------------------------------
Date: 23 Dec 2003 09:14:57 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Add Files to Zip File
Message-Id: <bs912h$dqb$1@mamenchi.zrz.TU-Berlin.DE>
Mike Flannigan <mikeflan@earthlink.net> wrote in comp.lang.perl.misc:
[Archive::Zip]
> I tried the code below right out of the example, but it
> gives the error:
> Can't locate object method "overwrite" via package "Archive::Zip::Archive"
> . . .
> at line 47.
>
> I guess I have a version problem here. But I think I also
My version 1.09 definitely has overwrite() in Archive::Zip::Archive.
> can't get my head around the terminology. When
> you say "create an archive from a disk file", you are
> basically saying create a working copy of the zip file
> that already contains zipped files. At least that is
> my understanding.
That's what I mean. As far as I can see,
Archive::Zip->new( 'existing_archive')
should do that.
Anno
------------------------------
Date: Tue, 23 Dec 2003 15:39:35 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: fork
Message-Id: <slrnbufho6.qbf.mgjv@martien.heliotrope.home>
[Removed comp.lang.perl from newsgroups, line, because it doesn't exist]
On Mon, 22 Dec 2003 10:29:14 -0800,
Jim Gibson <jgibson@mail.arc.nasa.gov> wrote:
> In article <bs76pq$4d99@imsp212.netvigator.com>, CwK <p12@bigfoot.com>
> wrote:
>
>> How to use fork() system function to fork multi child process at the same
>> time ?
>>
>> For example:
>>
>> Run a program to fork 5 child process at the same time and the parent must
>> wait until all child exit.
Run fork() 5 times, and run wait() in a loop until it returns -1.
>> The child do some thing like to read different file at the same time.
>>
>> Thanks
>>
>>
>
> Execute the fork call 5 times. You can't start 5 processes "at the same
> time", but you can do it quickly one after another. You will then need
> to execute the wait call 5 times in the parent process, one for each
> child.
I'm with you on this.
\begin{pedantry}
> No single process can do two or more different things
> simultaneously.
Except for processes with multiple threads, for example.
> Two or more processes can execute simultaneously only
> if you have more than one processor in your system.
or you have a single processor that can execute more than one
instruction/thread at once. What defines a "processor" is not limited to
what Intel produces.
\end{pedantry}
> Once you have a Perl program coded, and if it doesn't work, you should
> then post it here for additional help.
Agreed. The OP might also like to have a look at Parallel::ForkControl
or Parallel::ForkManager.
Those module might be overkill, and in that case, see above. or maybe
the following could be something to start with:
#!/usr/local/bin/perl -w
use strict;
for (1..5)
{
my $cpid = fork();
die unless defined $cpid;
if (! $cpid)
{
# This is the child
my $wait = int rand 4;
sleep $wait;
print "Child $$ exiting after $wait seconds\n";
exit;
}
}
# Just parent code, after this
while ((my $cpid = wait()) != -1)
{
print "Waited for child $cpid\n";
}
print "Parent Exiting\n";
Martien
--
|
Martien Verbruggen | Think of the average person. Half of the
| people out there are dumber.
|
------------------------------
Date: Tue, 23 Dec 2003 12:35:05 +0100
From: "Zoltan Kandi" <notpublic@restricted.com>
Subject: Re: fork
Message-Id: <60WFb.2$s04.9722@news.uswest.net>
Hi,
I've just run below code snippet proposed my Martien on my XP box and ... it
was working as expected on an ActiveState 5.6.1 build 633 installation.
I have read numerous times that Window$ does not support fork() and child
processes. What's now the full picture? To what extent can I use fork() in
my scripts?
Thanks in advance and a merry xmas to you all,
Zoltan
[snip]
> Those module might be overkill, and in that case, see above. or maybe
> the following could be something to start with:
>
> #!/usr/local/bin/perl -w
> use strict;
>
> for (1..5)
> {
> my $cpid = fork();
> die unless defined $cpid;
> if (! $cpid)
> {
> # This is the child
> my $wait = int rand 4;
> sleep $wait;
> print "Child $$ exiting after $wait seconds\n";
> exit;
> }
> }
>
> # Just parent code, after this
> while ((my $cpid = wait()) != -1)
> {
> print "Waited for child $cpid\n";
> }
>
> print "Parent Exiting\n";
>
> Martien
------------------------------
Date: Tue, 23 Dec 2003 08:14:13 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: help with file test
Message-Id: <zcXFb.6159$d%1.1341868@news20.bellglobal.com>
"Ragnar Hafstaš" <gnari@simnet.is> wrote in message
news:bs84cl$v40$1@news.simnet.is...
> "Matt Garrish" <matthew.garrish@sympatico.ca> wrote in message
> news:98MFb.4677$d%1.1045837@news20.bellglobal.com...
> >
> > Perl does not interpolate variables when you use the file test
operators,
> so
> > there's no need to be escaping any characters.
>
> can you explain what you mean by that. surely when executing:
> $x="foo";
> print "$x is a file\n" if -f $x;
> the $x is iterpolated
>
As noted in my followup, it wasn't the best sentence I've ever written. My
point was that there isn't any sort of recursive interpolation performed on
the value held by a variable. In your example, you could have just as easily
written $x = '$x' and then used $x to check for a directory called '$x'.
Otherwise you would get stuck in an endless loop as the value of $x could
never be resolved.
Matt
------------------------------
Date: Tue, 23 Dec 2003 08:25:43 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: help with file test
Message-Id: <lnXFb.6169$d%1.1349093@news20.bellglobal.com>
"Ragnar Hafstaš" <gnari@simnet.is> wrote in message
news:bs85dl$v4g$1@news.simnet.is...
>
> ok. then feel free to ignore my previous followup.
>
Too late... : )
Matt
------------------------------
Date: Tue, 23 Dec 2003 22:23:37 +1300
From: "Tintin" <me@privacy.net>
Subject: Re: Parsing File
Message-Id: <bs91kj$abecm$1@ID-172104.news.uni-berlin.de>
"John J. Trammell" <trammell+usenet@hypersloth.invalid> wrote in message
news:slrnbuecv8.58u.trammell+usenet@hypersloth.el-swifto.com.invalid...
> On Mon, 22 Dec 2003 17:50:43 GMT, James Willmore
> <jwillmore@remove.adelphia.net> wrote:
> > On 22 Dec 2003 07:37:19 -0800
> > genericax@hotmail.com (Sara) wrote:
> >> tartemp@epix.net (BrokenSaint) wrote in message
> >> news:<24813030.0312201921.3708d8f0@posting.google.com>...
> >
> >> die "duuuh gee Tenessee it wont even open!\n"
> >> unless open F, 'myBigoleFile.dat';
> >
> > You *really* mean
> >
> > my $filename = '/path/name_of_file';
> > open F, "$filename" or die "Can't open $filename: $!\n";
> ^ ^
> ^ ^
> >
> > right?
>
> Useless use of quotes; I've always liked:
>
> open(F,$filename) or die "Can't open '$filename': $!";
>
> but TMTOWDTI!
One could also say UUOB
open F,$filename or die "Can't open '$filename'.$!";
------------------------------
Date: 23 Dec 2003 10:18:42 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Parsing File
Message-Id: <bs94q2$g25$2@mamenchi.zrz.TU-Berlin.DE>
Tintin <me@privacy.net> wrote in comp.lang.perl.misc:
>
> "John J. Trammell" <trammell+usenet@hypersloth.invalid> wrote in message
> news:slrnbuecv8.58u.trammell+usenet@hypersloth.el-swifto.com.invalid...
> > On Mon, 22 Dec 2003 17:50:43 GMT, James Willmore
> > <jwillmore@remove.adelphia.net> wrote:
[snippage]
> > open(F,$filename) or die "Can't open '$filename': $!";
> >
> > but TMTOWDTI!
>
> One could also say UUOB
>
> open F,$filename or die "Can't open '$filename'.$!";
This is often the only place the actual file name is needed (the rest
of the program uses the handle). In that case, one may want to avoid
an explicit variable for the file name:
open my $f, $_ or die "Can't read '$_': $!" for '/some/file';
Anno
------------------------------
Date: Tue, 23 Dec 2003 13:22:30 +0000
From: Iain <iain@smokehythe.net>
Subject: PDF creation in Perl
Message-Id: <bs9fin$e6q$1@new-usenet.uk.sun.com>
Any recommendations, anyone?
Ta!
Iain.
--
Blow the smoke from my address if replying personally.
------------------------------
Date: Tue, 23 Dec 2003 14:43:46 +0100
From: Carsten Aulbert <carsten@welcomes-you.com>
Subject: Re: PDF creation in Perl
Message-Id: <bs9grr$al2pv$1@ID-213226.news.uni-berlin.de>
Iain wrote:
> Any recommendations, anyone?
wget -O- http://cpan.org/modules/01modules.index.html 2>/dev/null|grep -i pdf
hth
ca
------------------------------
Date: Tue, 23 Dec 2003 14:47:21 +0100
From: Calle Dybedahl <calle@cyberpomo.com>
Subject: Re: PDF creation in Perl
Message-Id: <86vfo74pee.fsf@ulthar.bisexualmenace.org>
>>>>> "iain" == iain <iain@smokehythe.net> writes:
> Any recommendations, anyone?
http://search.cpan.org/search?query=PDF&mode=all
--
Calle Dybedahl <calle@lysator.liu.se>
"I'd rather hang on to madness than normality" -- KaTe Bush
------------------------------
Date: 23 Dec 2003 12:19:05 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Perl DB question
Message-Id: <bs9brp$kd6$2@mamenchi.zrz.TU-Berlin.DE>
Sara <genericax@hotmail.com> wrote in comp.lang.perl.misc:
> I often want to break on the first line of a block, such as
>
>
> 21 while ($itsANiceDay)
> 22 {print "lets play outdoors\n";
> 23 $itsANiceDay = getWeatherReport();
> 24 }
>
>
> I can set a breakpoint on like 21 or 23, but why not 22? It looks like
> a legitimate place to break?
Line 22 contains both the start of a new block and an executable
statement. The new block can't take a break point. Using more
conventional bracing and indenting solves it:
21 while ($itsANiceDay) {
22 print "lets play outdoors\n";
23 $itsANiceDay = getWeatherReport();
24 }
Anno
------------------------------
Date: Wed, 17 Dec 2003 14:02:40 -0600
From: J.W. <jwngaa@att.net>
Subject: Re: Please critique this short script that scans a log file
Message-Id: <kgd1uv8g68rm6mr5ljphv0gp4i1btj0pfj@4ax.com>
On Wed, 17 Dec 2003 20:23:28 +0100, Matija Papec <perl@my-header.org>
wrote:
>> if (/^RC\s+:\s+(\d+)/) { # Return Code
>
>Since every line can match only once(?), you can use elsif's here to avoid
>unnecessary matches.
You are correct in use "elsif". This was a lapse in logic on my part.
This improves the performance of the script.
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 5972
***************************************