[19024] in Perl-Users-Digest
Perl-Users Digest, Issue: 1219 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 29 14:10:41 2001
Date: Fri, 29 Jun 2001 11:10:16 -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: <993838216-v10-i1219@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 29 Jun 2001 Volume: 10 Number: 1219
Today's topics:
Merging two hash tables <mvanle@dingoblue.net.au>
Re: Merging two hash tables <peb@bms.umist.ac.uk>
Re: Merging two hash tables <m.grimshaw@salford.ac.uk>
Re: Merging two hash tables <uri@sysarch.com>
Re: Merging two hash tables (Anno Siegel)
Re: Merging two hash tables (Tad McClellan)
Re: Merging two hash tables <uri@sysarch.com>
Re: Merging two hash tables <m.grimshaw@salford.ac.uk>
Re: Merging two hash tables (Anno Siegel)
Re: Merging two hash tables <m.grimshaw@salford.ac.uk>
Re: Merging two hash tables <mvanle@dingoblue.net.au>
Re: Merging two hash tables <mvanle@dingoblue.net.au>
Re: Merging two hash tables <flavell@mail.cern.ch>
Re: Merging two hash tables <joe+usenet@sunstarsys.com>
Re: My multi upload script isnt working right... <goldbb2@earthlink.net>
Re: Odd fork-problem was:Re: how can i get the output o (Thomas Schulze-Velmede)
Re: Passing Shell variables <e.broeren@food-express.nl>
perl test fails <redlamb@qwest.net>
Re: Perl with MS Access <cpryce@pryce.net>
Re: PERL won't load a file on Windows, but it will on U <somewhere@in.paradise.net>
Re: Perl-Mysql - inserting long fields <tfbiv@SPAMMENOTerols.com>
Re: pull out last line in a text file <uri@sysarch.com>
Re: Scanning a file in CGI <joe+usenet@sunstarsys.com>
Scheduling a task using perl <a246456@fmr.com>
Re: Silly pipe() question <goldbb2@earthlink.net>
Re: Textarea to file <ubl@schaffhausen.de>
Re: Textarea to file <godzilla@stomp.stomp.tokyo>
Re: Textarea to file <godzilla@stomp.stomp.tokyo>
Re: turbo perl <bowman@montana.com>
Re: turbo perl (Bernard El-Hagin)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 30 Jun 2001 00:53:49 +1000
From: "Minh Van Le" <mvanle@dingoblue.net.au>
Subject: Merging two hash tables
Message-Id: <20010630.005349.1186452551.1589@dingoblue.net.au>
why doesn't the following code work ?:
%table1 = qw(
a 1
b 2
c 3
);
%table2 = qw(
b 4
c 5
d 6
);
%table1{keys(%table2)} = values(%table2); # merge table2 into table1
------------------------------
Date: Fri, 29 Jun 2001 16:20:34 +0100
From: Paul Boardman <peb@bms.umist.ac.uk>
Subject: Re: Merging two hash tables
Message-Id: <3B3C9CC2.C1585C71@bms.umist.ac.uk>
Minh Van Le wrote:
>
> why doesn't the following code work ?:
>
> %table1 = qw(
> a 1
> b 2
> c 3
> );
>
> %table2 = qw(
> b 4
> c 5
> d 6
> );
>
> %table1{keys(%table2)} = values(%table2); # merge table2 into table1
why not just do
%table1 = (%table1, %table2);
?
HTH
Paul
------------------------------
Date: Fri, 29 Jun 2001 16:28:50 +0100
From: Mark Grimshaw <m.grimshaw@salford.ac.uk>
Subject: Re: Merging two hash tables
Message-Id: <3B3C9EB2.B240F6FF@salford.ac.uk>
Minh Van Le wrote:
>
> why doesn't the following code work ?:
>
> %table1 = qw(
> a 1
> b 2
> c 3
> );
>
> %table2 = qw(
> b 4
> c 5
> d 6
> );
>
> %table1{keys(%table2)} = values(%table2); # merge table2 into table1
Your script won't run because (using the -w flag), you'll get:
Can't use subscript on hash deref at ./table.pl line 25, near "%table2}"
(Did you mean $ or @ instead of %?)
Execution of ./table.pl aborted due to compilation errors.
As to whether your script (after correction) will do what you intend,
I've no idea.
------------------------------
Date: Fri, 29 Jun 2001 15:32:57 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Merging two hash tables
Message-Id: <x7hewz8fo5.fsf@home.sysarch.com>
>>>>> "MVL" == Minh Van Le <mvanle@dingoblue.net.au> writes:
MVL> why doesn't the following code work ?:
MVL> %table1 = qw(
MVL> a 1
MVL> b 2
MVL> c 3
MVL> );
MVL> %table2 = qw(
MVL> b 4
MVL> c 5
MVL> d 6
MVL> );
MVL> %table1{keys(%table2)} = values(%table2);
^
that % should be a @
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info: http://www.sysarch.com/perl/OOP_class.html
------------------------------
Date: 29 Jun 2001 15:44:54 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Merging two hash tables
Message-Id: <9hi7pm$au4$1@mamenchi.zrz.TU-Berlin.DE>
According to Paul Boardman <peb@bms.umist.ac.uk>:
> Minh Van Le wrote:
> >
> > why doesn't the following code work ?:
> >
> > %table1 = qw(
> > a 1
> > b 2
> > c 3
> > );
> >
> > %table2 = qw(
> > b 4
> > c 5
> > d 6
> > );
> >
> > %table1{keys(%table2)} = values(%table2); # merge table2 into table1
>
> why not just do
>
> %table1 = (%table1, %table2);
That's the standard idiom, but there's nothing wrong with the slice
method once the funny characters are right:
@table1{ keys %table2} = values %table2;
In fact, the latter doesn't expand %table1 and would be the method of
choice if many small tables must be merged into a big one.
Anno
------------------------------
Date: Fri, 29 Jun 2001 11:07:58 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Merging two hash tables
Message-Id: <slrn9jp6ee.o5d.tadmc@tadmc26.august.net>
Minh Van Le <mvanle@dingoblue.net.au> wrote:
>why doesn't the following code work ?:
Because it is a syntax error.
>%table1 = qw(
> a 1
> b 2
> c 3
>);
>
>%table2 = qw(
> b 4
> c 5
> d 6
>);
>
>%table1{keys(%table2)} = values(%table2); # merge table2 into table1
If you use the syntax for a "hash slice", then you would be all set:
@table1{keys(%table2)} = values(%table2);
^
^
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 29 Jun 2001 16:09:17 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Merging two hash tables
Message-Id: <x7d77n8dzm.fsf@home.sysarch.com>
>>>>> "MG" == Mark Grimshaw <m.grimshaw@salford.ac.uk> writes:
MG> Is this what you're looking for?
MG> while (($key, $value) = each %table2)
MG> {
MG> $table1{$key} = $value;
MG> }
MG> while (($key, $value) = each %table1)
MG> {
MG> print "$key : $value\n";
MG> }
gack! please read the other posts in this thread. the OP was off by ONE
char and didn't need that longer answer.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info: http://www.sysarch.com/perl/OOP_class.html
------------------------------
Date: Fri, 29 Jun 2001 17:27:05 +0100
From: Mark Grimshaw <m.grimshaw@salford.ac.uk>
Subject: Re: Merging two hash tables
Message-Id: <3B3CAC59.E0649B9E@salford.ac.uk>
Uri Guttman wrote:
>
> >>>>> "MG" == Mark Grimshaw <m.grimshaw@salford.ac.uk> writes:
>
> MG> Is this what you're looking for?
>
> MG> while (($key, $value) = each %table2)
> MG> {
> MG> $table1{$key} = $value;
> MG> }
> MG> while (($key, $value) = each %table1)
> MG> {
> MG> print "$key : $value\n";
> MG> }
>
> gack! please read the other posts in this thread. the OP was off by ONE
> char and didn't need that longer answer.
I think this was the second answer (following my first) and was
cancelled immediately I saw a better solution that was posted more or
less as I wrote mine.................. Check the time of posts maybe
before leaping to the attack?
------------------------------
Date: 29 Jun 2001 16:35:07 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Merging two hash tables
Message-Id: <9hianr$dtd$1@mamenchi.zrz.TU-Berlin.DE>
According to Mark Grimshaw <m.grimshaw@salford.ac.uk>:
>
>
> Uri Guttman wrote:
> >
> > >>>>> "MG" == Mark Grimshaw <m.grimshaw@salford.ac.uk> writes:
> >
> > MG> Is this what you're looking for?
> >
> > MG> while (($key, $value) = each %table2)
> > MG> {
> > MG> $table1{$key} = $value;
> > MG> }
> > MG> while (($key, $value) = each %table1)
> > MG> {
> > MG> print "$key : $value\n";
> > MG> }
> >
> > gack! please read the other posts in this thread. the OP was off by ONE
> > char and didn't need that longer answer.
>
> I think this was the second answer (following my first) and was
> cancelled immediately I saw a better solution that was posted more or
> less as I wrote mine.................. Check the time of posts maybe
> before leaping to the attack?
No, you learn how Usenet works. There is no way for a reader to
know that an article has been canceled before it's actually gone.
Once you've posted you're game. Sometimes canceling saves your
ass, sometimes it doesn't.
Anno
------------------------------
Date: Fri, 29 Jun 2001 17:42:21 +0100
From: Mark Grimshaw <m.grimshaw@salford.ac.uk>
Subject: Re: Merging two hash tables
Message-Id: <3B3CAFED.B42B20DC@salford.ac.uk>
> >
> > I think this was the second answer (following my first) and was
> > cancelled immediately I saw a better solution that was posted more or
> > less as I wrote mine.................. Check the time of posts maybe
> > before leaping to the attack?
>
> No, you learn how Usenet works. There is no way for a reader to
> know that an article has been canceled before it's actually gone.
> Once you've posted you're game. Sometimes canceling saves your
> ass, sometimes it doesn't.
>
OK, that lesson learnt - but it also seems the displayed time of post is
not actually the time it was posted. My first response (about the
error) I sent only a few minutes after the OP followed immediately by my
second gack! post which crossed with the other solution. As far as I
was concerned (maybe usenet works this way :)), I had no other posts to
read first. Hence I feel justified in defending myself and in taking
steps to try to remove my gack! post as quickly as possible.
------------------------------
Date: Sat, 30 Jun 2001 03:05:56 +1000
From: "Minh Van Le" <mvanle@dingoblue.net.au>
Subject: Re: Merging two hash tables
Message-Id: <20010630.030555.1351797369.1589@dingoblue.net.au>
In article <slrn9jp6ee.o5d.tadmc@tadmc26.august.net>, "Tad McClellan"
<tadmc@augustmail.com> wrote:
> Minh Van Le <mvanle@dingoblue.net.au> wrote:
>
>>why doesn't the following code work ?:
>
>
> Because it is a syntax error.
>
>
>>%table1 = qw(
>> a 1
>> b 2
>> c 3
>>);
>>
>>%table2 = qw(
>> b 4
>> c 5
>> d 6
>>);
>>
>>%table1{keys(%table2)} = values(%table2); # merge table2 into table1
>
>
> If you use the syntax for a "hash slice", then you would be all set:
>
> @table1{keys(%table2)} = values(%table2); ^ ^
cryke. it says here, "%league{keys %score} = values %score" on pg.70 of
Learning Perl, 2nd Edition.
i was going to test $, and maybe @. but being the lazy programmer that i
am, and also checking the errata on the book and found no mention of
mistakes; decided to ask here while i stopped side-tracking myself on
syntax problems and moved on to the next exercises :)
... ok so it was in lperl2.unconfirmed, not lperl2.*97 :)
------------------------------
Date: Sat, 30 Jun 2001 03:12:31 +1000
From: "Minh Van Le" <mvanle@dingoblue.net.au>
Subject: Re: Merging two hash tables
Message-Id: <20010630.031228.933110197.1589@dingoblue.net.au>
In article <3B3C9CC2.C1585C71@bms.umist.ac.uk>, "Paul Boardman"
<peb@bms.umist.ac.uk> wrote:
> Minh Van Le wrote:
>>
>> why doesn't the following code work ?:
>>
>> %table1 = qw(
>> a 1
>> b 2
>> c 3
>> );
>>
>> %table2 = qw(
>> b 4
>> c 5
>> d 6
>> );
>>
>> %table1{keys(%table2)} = values(%table2); # merge table2 into
>> table1
>
> why not just do
>
> %table1 = (%table1, %table2);
>
> ?
@table1{keys(%table2)} = values(%table2);
is equivalent to
%table1 = (%table1, %table2);
but it says that the latter is a "much slower operation", according to
Learning Perl 2nd Edition, pg.70.
------------------------------
Date: Fri, 29 Jun 2001 19:31:44 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Merging two hash tables
Message-Id: <Pine.LNX.4.30.0106291924210.32195-100000@lxplus003.cern.ch>
On Sat, 30 Jun 2001, Minh Van Le wrote:
> > @table1{keys(%table2)} = values(%table2);
>
> cryke. it says here, "%league{keys %score} = values %score" on pg.70 of
> Learning Perl, 2nd Edition.
My copy says on page 70
@league{{keys %score} = values %score;
Printing History says July 1997: Second Edition.
Uh-uh: see http://www.oreilly.com/catalog/lperl2/errata/lperl2.499
{70} In the 5th paragraph in "Hash Slices" section, line of code used
to read:
@league{keys %score} = values %score;
It now reads:
%league{keys %score} = values %score;
------------------------------
Date: 29 Jun 2001 13:58:44 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Merging two hash tables
Message-Id: <m3ithfp3qj.fsf@mumonkan.sunstarsys.com>
"Minh Van Le" <mvanle@dingoblue.net.au> writes:
> In article <3B3C9CC2.C1585C71@bms.umist.ac.uk>, "Paul Boardman"
> <peb@bms.umist.ac.uk> wrote:
>
> > Minh Van Le wrote:
> >>
> >> why doesn't the following code work ?:
> >>
> >> %table1 = qw(
> >> a 1
> >> b 2
> >> c 3
> >> );
> >>
> >> %table2 = qw(
> >> b 4
> >> c 5
> >> d 6
> >> );
Why not use an annomaly? :-)
my @annomaly = map { $_ => $_ + 3 } 0 .. 2;
my %table1 = ("a".."c" => 1 .. 3) [ @annomaly ];
my %table2 = ("b".."d" => 4 .. 6) [ @annomaly ];
[...]
> @table1{keys(%table2)} = values(%table2);
>
> is equivalent to
>
> %table1 = (%table1, %table2);
Note that your keys overlap, so either way the values
from %table2 will replace the originals in %table1. If
instead you'd like the original values in %table1 to be
preserved, you could either do
%table1 = (%table2, %table1); # simple way
or
my @newkeys = grep{ not exists $table1{$_} } keys %table2;
@table1{ @newkeys } = @table2{ @newkeys };
HTH
--
Joe Schaefer "Buy land. They've stopped making it."
--Mark Twain
------------------------------
Date: Fri, 29 Jun 2001 09:40:05 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: My multi upload script isnt working right...
Message-Id: <3B3C8535.E418BBA3@earthlink.net>
krakle wrote:
>
> Hello! I am creating a file managment tool in perl (CGI). I'm pretty
> much finished with the script with all of its features except for
> uploading. I just cant get the uploading part to work at all. It
> creates an EMPTY file...
>
[snip]
> } elsif ($FORM{'action'} eq "upload") {
> for ($upnum = 1; $upnum <= $FORM{'total'}; $upnum++) {
> $file_upload = $FORM{'upload_file_' . $upnum};
> $file_rename = $FORM{'rename_file_' . $upnum};
> if ($file_upload ne "") {
> if (open (UPLOAD, ">$dir_path/$file_rename")) {
> while (read($file_upload, $data, 1024)) {
> print UPLOAD $data; # Print buffer
> }
> close (UPLOAD);
Have you checked that $file_upload is not an empty file?
my $size = -s $file_upload;
push @success, "Recieved file $upnum, size $size\n";
--
The longer a man is wrong, the surer he is that he's right.
------------------------------
Date: 29 Jun 2001 09:21:14 -0700
From: tsv.werbung@web.de (Thomas Schulze-Velmede)
Subject: Re: Odd fork-problem was:Re: how can i get the output of a forked child?
Message-Id: <227269e2.0106290821.4c8f575e@posting.google.com>
Hi Villy,
you are right, but unfortunately this is NOT the problem. The problem
is that the STDIN file descriptor gets confused. (I haven't tracked
that done yet. For details, look at the older article I mentioned in
the previous post. Roughly: Perl do a llseek in the child process
which seems to effect the father process.)
Example:
Take this code snippet:
----------------------------
#!/usr/bin/perl
#
my @childIDs;
open (LIST, "<$ARGV[0]") or die "Can't open file";
$linecounter=0;
while(<LIST>){
$linecounter++;
print "Father processing line $linecounter: $_\n";
if($pid = fork){
# parent here
next;
} elsif (defined $pid){
# child here
$pid = getppid;
print "Son $$ of $pid prints: $_";
push @childIDs, $$;
exit;
} else {
die "Can't fork, stopped";
}
}
print "This is process $$ waiting for all childs to complete\n";
foreach $id (@childIDs){
waitpid $id,"";
}
close LIST;
print "done\n";
----------------------------
and try it on a Solaris box (It tried diff Perl 5.00x-versions under
Sol 5.6, 7 and 8 on diff. ULTRA-machines) with a file which contains
this three lines:
first_line
sec_line
third_line
And you`ll get something like this:
----------------------------
Father processing line 1: first_line
Son 13733 of 13732 prints: first_line
Father processing line 2: sec_line
Son 13734 of 13732 prints: sec_line
Father processing line 3: third_line
Son 13735 of 13732 prints: third_line
Father processing line 4: first_line
Son 13736 of 13732 prints: first_line
Father processing line 5: sec_line
Son 13737 of 13732 prints: sec_line
Father processing line 6: third_line
Son 13738 of 13732 prints: third_line
Father processing line 7: first_line
Father processing line 8: sec_line
Father processing line 9: third_line
Son 13739 of 13732 prints: first_line
Son 13740 of 13732 prints: sec_line
Son 13741 of 13732 prints: third_line
Father processing line 10: first_line
Son 13742 of 13732 prints: first_line
Father processing line 11: sec_line
Son 13743 of 13732 prints: sec_line
Father processing line 12: third_line
Father processing line 13: first_line
Father processing line 14: sec_line
Son 13744 of 13732 prints: third_line
Son 13745 of 13732 prints: first_line
Son 13746 of 13732 prints: sec_line
Father processing line 15: third_line
Son 13747 of 13732 prints: third_line
Father processing line 16: first_line
Father processing line 17: sec_line
Father processing line 18: third_line
This is process 13732 waiting for all childs to complete
done
----------------------------
If anybody has an idea, what's going on: Please let me know! If it's a
Solaris bug, than I may open a case by Sun... If it's a Perl bug, than
of course it should be fixed.
I would really appreciate anybodys help on this problem.
Thanks in advance
Best regards
Thomas
------------------------------
Date: Fri, 29 Jun 2001 16:57:50 +0200
From: "Eugene" <e.broeren@food-express.nl>
Subject: Re: Passing Shell variables
Message-Id: <9hi51p$c6a$1@ncc1701.cistron.net>
Thanks for the help.
------------------------------
Date: Fri, 29 Jun 2001 16:29:13 GMT
From: "Redlamb" <redlamb@qwest.net>
Subject: perl test fails
Message-Id: <t12%6.1154$5d.498859@newshog.newsread.com>
Well, I hope that I ask this question in the correct place. I am new to perl
and still need to finish installing it. After running a make test, I ran
into 3 errors. One of the errors said to ignore it. The other two had to do
with syslog. After running ./perl lib/syslog.t, I found that it failed test
2 and 3.After looking at the test, I was able to modify test 2 so that it
worked and am still working on 3. My question is, if I change these tests to
get them to work, does that still mean that since the original test failed,
I should not install or can I install? By the way, I'm running NetBSD 1.5. I
hope that this makes sense. Thanks in advance.
------------------------------
Date: Fri, 29 Jun 2001 11:25:22 -0500
From: Chris <cpryce@pryce.net>
Subject: Re: Perl with MS Access
Message-Id: <B7621622.79D1%cpryce@pryce.net>
in article 9hfkfm$qo2$1@tilde.csc.ti.com, T.H. at tambaa@no.spam.yahoo.com
wrote on 06/28/2001 11:08 AM:
> Anyone know of a good web resource with sample Perl scripts on manipulating
> MS Access databases?
>
> TIA
> T.H.
>
Try :
http://tlowery.hypermart.net/perl_dbi_dbd_faq.html#HowDoIAccessMSWindowsDB
------------------------------
Date: Fri, 29 Jun 2001 23:24:18 +1000
From: "Tintin" <somewhere@in.paradise.net>
Subject: Re: PERL won't load a file on Windows, but it will on UNIX
Message-Id: <al%_6.15$Ps2.819233@news.interact.net.au>
"Joseph C. Slater" <joseph.slater@wright.edu> wrote in message
news:joseph.slater-095A31.11565528062001@mercury.wright.edu...
> The following script won't work on Windows, but it will on UNIX and
> MacOS. The text file is never loaded into the variable. Isn't PERL
> supposed to be platform independent? The line "print(@textfile);"
> returns nothing. I'm using Active PERL on wind '98.
Perl is (mostly) platform independent, however it doesn't mean you can get
rid of any error checking.
You can't guarantee the open will succeed.
------------------------------
Date: Fri, 29 Jun 2001 13:18:04 -0400
From: Tom Bates <tfbiv@SPAMMENOTerols.com>
Subject: Re: Perl-Mysql - inserting long fields
Message-Id: <ardpjt8lpakjrfm2pn5jla3nss816ondug@4ax.com>
On Wed, 27 Jun 2001 20:38:23 +1000, "Gregory Toomey" <gtoomey@usa.net>
wrote:
>Hi everyone. I'm sure that this has been asked lots of times before but bear
>with me!
>
>I just upgraded my web hosting to get Perl and mysql.
>
>I want a general Perl script to insert/update mysql tables. I have found a
>script called Mysqledb http://www.solution4web.com/mysqlwdb/ which works but
>is very basic.
>The problem is that the browser fields in this script are about 16 chars
>long. I have some "text" fields my my database (length to 64K), and may need
>to write a small essay!
>
>Are there any Perl scripts that allow allow insert/update of mysql tables,
>and will accommodate long text fields?
>
>Thanks
>
>Gregory Toomey
>
In addition to the things already mentioned by others here, you will
also need to set some DBI variables to get really long data fields to
work properly. Do
perldoc DBI
and look for LongReadLen and LongTruncOk.
Tom
------------------------------
Date: Fri, 29 Jun 2001 15:31:34 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: pull out last line in a text file
Message-Id: <x7k81v8fqh.fsf@home.sysarch.com>
>>>>> "DJ" == Damian James <damian@qimr.edu.au> writes:
>> print @{[<>]}[-3 .. -1];
DJ> A way to do this without reading the *whole* file into RAM:
DJ> my @lines = ('') x 3;
DJ> shift @lines, push(@lines, $_) while <>;
DJ> print @lines;
that still reads the whole file even if only a line at a time.
i appreciate the golf like code and such, but why read anything more
than you have to? use the File::ReadBackwards module as it is designed
for this very problem and is much more efficient, cleaner and you don't
have to think about odd code.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info: http://www.sysarch.com/perl/OOP_class.html
------------------------------
Date: 29 Jun 2001 09:32:58 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Scanning a file in CGI
Message-Id: <m3ofr7pg1h.fsf@mumonkan.sunstarsys.com>
"Wyzelli" <wyzelli@yahoo.com> writes:
> But try a 1-2 Mb file read and process with the line by line method compared
> to the read all into an array method, and you can often see signinficant
> performance improvements, at the cost of system resources.
Can you back this up? I just tested
something() while <FILE>;
against
my @f = <FILE>;
something() foreach @f;
It is the latter idiom that appears here with obscene regularity, and
as I understood him, that's what Anno was referring to. On a 1.5 MB
Apache logfile, the performance difference was roughly 3 to 1 in favor
of the standard idiom.
#!/usr/bin/perl -w
use Benchmark;
open FILE, shift or die "Can't open file: $!";
printf "File size=%d bytes\n" => -s FILE;
timethese -10, {
readline=>q{seek FILE,0,0; chomp while <FILE>},
aryslurp=>q{seek FILE,0,0; chomp(my @f=<FILE>)},
scrslurp=>q{seek FILE,0,0; local $/; $_=<FILE>; y/\n//d},
fstslurp=>q{seek FILE,0,0; read FILE,$_,-s FILE;y/\n//d},
}
__END__
=>
File size=1402650 bytes
Benchmark: running aryslurp, fstslurp, readline, scrslurp,
each for at least 10 CPU seconds...
aryslurp: (10.34 usr + 0.08 sys = 10.42 CPU) @ 2.11/s (n=22)
fstslurp: ( 9.93 usr + 0.22 sys = 10.15 CPU) @ 6.80/s (n=69)
readline: ( 9.86 usr + 0.28 sys = 10.14 CPU) @ 6.51/s (n=66)
scrslurp: (10.40 usr + 0.23 sys = 10.63 CPU) @ 4.89/s (n=52)
> But if you have the resources to spare, it can be an advantage to do
> this, as long as you are careful of the caveats.
AFAICT, it seems like you're just trading potentially fewer disk cache
misses for feverish malloc(3) or realloc(3) calls. Even fstslurp above,
which minimizes all system calls, barely outperforms the standard idiom
on my box. Manipulating the unwieldy scalar in $_ appears to take all
the wind out of its sail.
--
Joe Schaefer "When the end of the world comes, I want to be in Cincinnati.
Everything happens ten years later there."
--Mark Twain
------------------------------
Date: Fri, 29 Jun 2001 12:00:10 -0400
From: a246456 <a246456@fmr.com>
Subject: Scheduling a task using perl
Message-Id: <3B3CA60A.BDA71254@fmr.com>
I am trying to write a perl program which adds task scheduler on all NT
servers. I am not talking about At job, bcos the userid should belong to
administrators group or Server operators group. I want to do this
through Mstask (task scheduler). Is it possible, if so could you please
let me know.
Thanks in advance.
paulur
------------------------------
Date: Fri, 29 Jun 2001 09:21:34 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Silly pipe() question
Message-Id: <3B3C80DE.A8F0C8E9@earthlink.net>
> On Sat, 2 Jun 2001, abigail@foad.org wrote:
[snip]
> > Furthermore, if pipe() would be argument less, returning both sides
> > of the pipe(), how should such a modified pipe act in scalar
> > context?
Return a reference to an array containing both ends of the pipe. Think
of it as a kind of poor man's IO::Pipe. Here's an example using it:
sub RD() { 0 }
sub WR() { 1 }
my $p_to_c = pipe or die "Couldn't make a pipe: $!\n";
my $c_to_p = pipe or die "Couldn't make a pipe: $!\n";
if( my $pid = fork ) {
$p_to_c = $p_to_c->[WR];
$c_to_p = $c_to_p->[RD];
print $p_to_c "parent sent this to child\n";
print "parent got: ", <$c_to_p>;
close $_ for( $p_to_c, $c_to_p );
} elsif( defined $pid ) {
$c_to_p = $c_to_p->[WR];
$p_to_c = $p_to_c->[RD];
print "child got: ", <$p_to_c>\n";
print $c_to_p "child sent this to parent\n";
exit;
} else {
die "Couldn't fork: $!\n";
}
When the ref count of a handle goes to zero, it gets closed. Because of
this, there are two implicit closes in each of the parent and child, at
the places where we make the assignments.
--
The longer a man is wrong, the surer he is that he's right.
------------------------------
Date: Fri, 29 Jun 2001 15:26:40 +0100
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: Textarea to file
Message-Id: <3B3C9021.71D7D997@schaffhausen.de>
Benjamin Goldberg schrieb:
> The module CGI.pm exists for a reason. Use it unless you have a d**m
> good reason not to.
The op might also want to look at the standard HTML::Entities
->malte
------------------------------
Date: Fri, 29 Jun 2001 09:34:47 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Textarea to file
Message-Id: <3B3CAE27.DCC40BC2@stomp.stomp.tokyo>
Benjamin Goldberg wrote:
(snipped bad code and bad advice)
> # always, yes, always, check the return value of open.
More important, always test your code to be sure
it is good code. Posting code which contains fatal
errors benefits none.
Undefined subroutine &main::param called at c:/apache/users//test/test3.pl line 9.
Godzilla!
------------------------------
Date: Fri, 29 Jun 2001 10:42:06 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Textarea to file
Message-Id: <3B3CBDEE.470E901@stomp.stomp.tokyo>
TuNNe|ing wrote:
> This is some EDITED sample code I got from Perl 5 by Example by David
> Medinets.
(snipped code)
Using very similar Perl 4 style coding, there is a method
which will run not quite twice as fast as your edited
textbook Perl 5 example and, my method will correctly
remove form action generated carriage return / newline
\r\n combinations where your textbook code does not. My
code also provides direct access to key / value pairs
where your textbook code requires hash access to
key / value pairs.
I have included conversion to <BR>\n within my code to
maintain equality in controls and to provide a superior
document source print along with an if / else for GET or
POST method. Normally I use only one or the other
tailored to a specific form action request method.
name1 is my method
name2 is your textbook method
Godzilla!
--
#!perl
print "Content-type: text/plain\n\n";
use Benchmark;
print "Run One:\n\n";
&Time;
print "\n\nRun Two:\n\n";
&Time;
print "\n\nRun Three:\n\n";
&Time;
sub Time
{
timethese (100000,
{
'name1' =>
'$ENV{QUERY_STRING} = "Text_Area=Godzilla Rocks!";
&Akostininchi_Ithana;
sub Akostininchi_Ithana
{
if ($ENV{REQUEST_METHOD} eq "GET")
{ $in = $ENV{QUERY_STRING}; }
else
{ read (STDIN, $in, $ENV{CONTENT_LENGTH}); }
local (*in) = @_ if @_;
local ($i, $key, $value);
@in = split (/&/, $in);
foreach $i (0 .. $#in)
{
$in[$i] =~ s/\+/ /g;
($key, $value) = split (/=/, $in[$i], 2);
($value eq "") && next;
$key =~ s/%(..)/pack ("c",hex($1))/ge;
$value =~ s/%(..)/pack ("c",hex($1))/ge;
$value =~ s/\r\n/<BR>\n/g;
$in{$key} .= "\0" if (defined($in{$key}));
$in{$key} .= $value;
return 1;
}
}',
'name2' =>
'$ENV{QUERY_STRING} = "Text_Area=Godzilla Rocks!";
&getFormData;
sub getFormData
{
my($hashRef) = shift;
my($buffer) = "";
if ($ENV{REQUEST_METHOD} eq "GET")
{ $buffer = $ENV{QUERY_STRING}; }
else
{ read(STDIN, $buffer, $ENV{CONTENT_LENGTH}); }
foreach (split(/&/, $buffer))
{
my($key, $value) = split(/=/, $_);
$key = decodeURL($key);
$value = decodeURL($value);
$value =~ s!\n!<br>!g;
%{$hashRef}->{$key} = $value;
}
}
sub decodeURL
{
$_ = shift;
tr/+/ /;
s/%(..)/pack("c", hex($1))/eg;
return($_);
}',
} );
}
exit;
PRINTED RESULTS:
________________
Run One:
Benchmark: timing 100000 iterations of name1, name2...
name1: 5 wallclock secs ( 4.78 usr + 0.00 sys = 4.78 CPU) @ 20920.50/s
name2: 9 wallclock secs ( 8.07 usr + 0.00 sys = 8.07 CPU) @ 12391.57/s
Run Two:
Benchmark: timing 100000 iterations of name1, name2...
name1: 5 wallclock secs ( 4.83 usr + 0.00 sys = 4.83 CPU) @ 20703.93/s
name2: 8 wallclock secs ( 8.08 usr + 0.00 sys = 8.08 CPU) @ 12376.24/s
Run Three:
Benchmark: timing 100000 iterations of name1, name2...
name1: 5 wallclock secs ( 4.89 usr + 0.00 sys = 4.89 CPU) @ 20449.90/s
name2: 8 wallclock secs ( 8.18 usr + 0.00 sys = 8.18 CPU) @ 12224.94/s
------------------------------
Date: Fri, 29 Jun 2001 07:12:00 -0600
From: "bowman" <bowman@montana.com>
Subject: Re: turbo perl
Message-Id: <06%_6.3187$541.948@newsfeed.slurp.net>
"Patrick Erler" <perler@yahoo.com> wrote in message
news:Xns90CF6E4991F0Afuyyehcesyrdx@62.153.159.134...
>
> i think you all don't get the point... there is a difference between
> looking at help pages with less and having a hyperlinked textmode help...
i
> think you never experienced that kind of comfort you have in borlands
> IDEs..
The Borland Turbo products were very impressive in that regard. I remember
seeing the ads in Byte and sending off my $49.95 figuring "this must be a
rip off". It wasn't. Then there is DevStudio's F1 key.
But: in vim, a 'K' brings up the man page. Ok, it isn't html, but it works.
as another poster mentioned, a little tweak in your .vimrc, if it hasn't
been done already and is lurking on Dr. Chip's page, will pull in the
perlfunc page for the function in question. A more ambitious solution might
be indexing the AS html version and pulling pages up in a browser.
And then there is Komodo, still a young lizard but showing promise.
------------------------------
Date: Fri, 29 Jun 2001 13:27:06 +0000 (UTC)
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: turbo perl
Message-Id: <slrn9jp050.112.bernard.el-hagin@gdndev25.lido-tech>
On Fri, 29 Jun 2001 07:12:00 -0600, bowman <bowman@montana.com> wrote:
>
>"Patrick Erler" <perler@yahoo.com> wrote in message
>news:Xns90CF6E4991F0Afuyyehcesyrdx@62.153.159.134...
>>
>> i think you all don't get the point... there is a difference between
>> looking at help pages with less and having a hyperlinked textmode help...
>i
>> think you never experienced that kind of comfort you have in borlands
>> IDEs..
>
>The Borland Turbo products were very impressive in that regard. I remember
>seeing the ads in Byte and sending off my $49.95 figuring "this must be a
>rip off".
Why did you send the cash if you figured you'd get ripped off? :-)
Cheers,
Bernard
--
perl -l54e's yyw q q tvmrx "h\ywx ersxliv zivp legoiv"qiy;y #a-zA-Z#d-gu-z#
chefghijklmnopqrstuvwxyzcJab-def-uPwxyzc;s j j s u u s t t s r r s
ppevalpereeteueje'
------------------------------
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 1219
***************************************