[19488] in Perl-Users-Digest
Perl-Users Digest, Issue: 1683 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Sep 3 06:05:44 2001
Date: Mon, 3 Sep 2001 03:05:08 -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: <999511508-v10-i1683@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 3 Sep 2001 Volume: 10 Number: 1683
Today's topics:
Re: AoH - sorry for the no subj (TuNNe|ing)
Re: AoH - sorry for the no subj <godzilla@stomp.stomp.tokyo>
Re: AoH - sorry for the no subj <godzilla@stomp.stomp.tokyo>
Can i do the divx stuff with perl? (Dav Lam)
Re: can't set permission on directory <tony_curtis32@yahoo.com>
Re: Converting Perl to C <bart.lateur@skynet.be>
Re: D'oh! It does what I said, not what I want <goldbb2@earthlink.net>
Re: Godzilla DOS Perl Script Timer <Thomas@Baetzler.de>
Re: How to connect to Oracle DB using perl (Helgi Briem)
Re: Installing perl-mysql interface <mfrick@chariot.net.au>
Re: Is there a better way of righting this... <wyzelli@yahoo.com>
performing commands through perl.. <webmaster@remove...this....whatevah.com>
Re: performing commands through perl.. <Thomas@Baetzler.de>
perl extensions in C, special malloc libraries <Andrew.Torda@anu.edu.au>
Re: Perl handcoded? <dan@tuatha.sidhe.org>
Re: Problems with fixed-length random access databases. <goldbb2@earthlink.net>
Re: random link from web page <goldbb2@earthlink.net>
Re: Recommendations for a PERL editor (Yves Orton)
Re: registration worries (Mr. Green)
Re: sysread problem on socket <goldbb2@earthlink.net>
Re: Using less memory for hashes <jonni@ifm.liu.nospam.se>
Re: Using less memory for hashes <goldbb2@earthlink.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 03 Sep 2001 03:29:31 GMT
From: troll@gimptroll.com (TuNNe|ing)
Subject: Re: AoH - sorry for the no subj
Message-Id: <3b92f640.24640823@news.coserv.net>
OK...sorry for the inconsiderate minor mistakes in my example code.
However, it was a conceptual question. I am having a little trouble
grasping some of the more complicated data structures.
Tad, I always "use strict;" during development. Would it be better if
I stated before hand "this is not the entire program"? I usually try
to only place the code that is relevant to my dilema to the group. I
have seen people post pages of code that make me gag, so I try to be
as brief as possible. I guess due to that I leave out things like "use
strict;" and when I cc&p my code for "examples", I tend to miss the
minor details and focus on the higher level thought processes.
With all that crap said, I would like to make it as easy as possible
for your assistance. Thanks for the _DATA_ idea. And I'll make sure
and test my code from now on so "relative newbies" don't find
mistakes.
Word to the mother,
TuNNe|ing
p.s. oh yea..thanks for the solution Kurt.
------------------------------
Date: Sun, 02 Sep 2001 20:17:06 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: AoH - sorry for the no subj
Message-Id: <3B92F632.BFBA1755@stomp.stomp.tokyo>
TuNNe|ing wrote:
(snipped)
I have elected to not comment on your code.
> Tad, I always "use strict;" during development.
Work towards an ability to write Perl programs
without using strict. This will lead to your
being a better programmer and will lead to an
ability to write significantly more efficient
scripts. Use of strict is mostly ok save for
forcing you to write slower less efficient code,
but it can become a very serious crutch, a right
crutch with warnings being a left crutch.
> Thanks for the _DATA_ idea.
Use of _DATA_ works well if you know how to
use this format correctly.
However, there is a very serious problem with
using this _DATA_ format no Perl 5 Cargo Cultists
will mention; this would be sacrilege to mention
any negative aspects of Perl 5 Cargo Cult Dogma.
There have been times I have been yelled at by
regulars here for not using _DATA_ in my test
scripts when it should be obvious to them what
will happen if used. These are times I do not
use _DATA_ for a good reason, a good reason
about which, most here have no clue.
Give my test script a whirl.
Godzilla! Queen Of Perl Heretics.
--
#!perl
while (<DATA>)
{ print "\n\n$_\n\n"; }
seek (DATA, 0, 0);
while (<DATA>)
{ print $_; }
__DATA__
Godzilla Rocks And Rolls!
------------------------------
Date: Sun, 02 Sep 2001 21:51:38 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: AoH - sorry for the no subj
Message-Id: <3B930C5A.19308725@stomp.stomp.tokyo>
David Hilsee wrote:
> Godzilla! wrote:
> > TuNNe|ing wrote:
(snipped)
> > > Thanks for the _DATA_ idea.
> > Use of _DATA_ works well if you know how to
> > use this format correctly.
> > However, there is a very serious problem with
> > using this _DATA_ format no Perl 5 Cargo Cultists
> > will mention; this would be sacrilege to mention
> > any negative aspects of Perl 5 Cargo Cult Dogma.
> > Give my test script a whirl.
> If you wanted to still use __DATA__, then why not
> my $start = tell(DATA);
> while (<DATA>) { print; }
> print "*****************\n"
> seek DATA, $start, 0;
> while (<DATA>) { print; }
This works very well, for those aware of this method.
You need to add a semicolon after your asterisk print.
Interestingly enough, I view this as a bug with Perl.
For _DATA_ syntax, perl core should be coded in such
a way to recognize and store "character zero" so this
seek glitch won't jump out and surprise people. This
one time event of reading _DATA_ renders this method
virtually useless for many circumstances; a lot of
extra coding must be added to use it more than once.
Your exemplifying this adds emphasis to this problem
of people here telling people to do this, to do that,
and neglecting to comment on positive and negative
points about any given methodology.
There are two recent examples of this, one classic
and one, well hidden. Literally all here say you
must use CGI.poopmaker. They never say this usage
will cause a script to run a minimum of three times
slower than other methods and, often as much as ten
to twenty times slower.
This hidden problem I mention, exemplified recently,
a person taunted how great security is with usage
of CGI.poopmaker, indicating limiting on content
length. He failed to mention this needs to be set.
While I am on a tirade, recently I demonstrated how
use of warnings will crash perl core and crash a
typical Windows system, when running a large and
complex cgi script with some efficient rogue methods.
All here fail to ever mention myriad problems which
are inherent to warnings.
For the originating author's code, from what I read,
there is nothing indicating a hash is even needed.
There is a lot of slow unwarranted coding. Nonetheless,
none mentioned this to him. Go figure.
Bottom line is a disservice is performed by those
who chant Perl 5 Cargo Cult Dogma, like Borg geeks.
Godzilla!
--
21:32:33 09/02/2001 - RESTRICTED FILE REDIRECT:
- DNS: lsiedm-fw.lsiedm.com - IPA: 207.167.12.182
- System:
- Redirect URL: /default.ida
------------------------------
Date: 3 Sep 2001 01:01:58 -0700
From: crud@hongkong.com (Dav Lam)
Subject: Can i do the divx stuff with perl?
Message-Id: <fc25f4f2.0109030001.3d255c60@posting.google.com>
I'm wondering is it possible to do conversion between common video
formats(avi, mpeg, etc...) and divx...
Is there a module can handle this kind of job?
Or have anybody ever heard some similar command line program that i
can integrated them into perl script?
Thanks in advance~~
------------------------------
Date: Sun, 02 Sep 2001 22:38:51 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: can't set permission on directory
Message-Id: <87elpp3q13.fsf@limey.hpcc.uh.edu>
>> On Sun, 02 Sep 2001 08:32:02 GMT,
>> nils-eric@telia.com (Nils-Eric Pettersson) said:
> Perhaps this is a unix-problem but I have no problem
> doing this in Unix direct... so I don't think so.
> When I in Perl sets the permission on a directory
> chmod 777 directory1;
> nothong hapends. Even if the parent directory of
> directory1 is set to 777.
Especially when dealing with objects outside of the perl
program (like a filesystem in this case) you need to check
the result of the operation. If chmod() fails, ask perl
to tell you what is in the $! variable. See "perldoc
perlvar" for more on $!.
chmod ... or die "chmod failed: $!\n";
My antennae twitch and I get the feeling this might be a
CGI question in disguise. If so, there's a whole slew of
other issues. Some of these are discussed at:
http://www.htmlhelp.com/faq/cgifaq.1.html#16
In any case, you are probably correct: this is not a perl
issue per se, but you can get perl to tell you more about
what is going on before working on where best to continue
to ask questions.
hth
t
--
Yes way! Mmmmkay?
------------------------------
Date: Mon, 03 Sep 2001 08:53:08 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Converting Perl to C
Message-Id: <n6h6pt868f0788bgcqt4v8df1ave618s8f@4ax.com>
Tassilo von Parseval wrote:
>> And why do you want to do that?
>
>Oh, there may be reasons for doing that, be it for the sake of writing a
>closed-source program or just being able to run this particular program
>on a similar machine having no Perl interpreter by its hand.
For this, perl2exe and perlapp work just fine.
--
Bart.
------------------------------
Date: Mon, 03 Sep 2001 02:30:52 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: D'oh! It does what I said, not what I want
Message-Id: <3B93239C.E4CBEB1A@earthlink.net>
Lou Moran wrote:
>
> I have writtent the script below and I think my problem with it is the
> "until" b/c what is happening is that my (hmm that's funnny) variables
> are getting their information once. But I want them to get the
> information over and over again. What would work better?
#!/usr/bin/perl -w
use strict;
use diagnostics;
my @pings = (
"XXX.XXX.XXX.XXX -n 1",
"yahoo.com -n 25",
"132.163.4.101 -n 25",
);
my $dashes = "-" x 28;
for( my $numb = 18501; $numb != 1; --$numb ) {
foreach $ping ( @pings ) {
print $dashes, "\n";
system "ping $_";
}
print scalar localtime, "\n", $dashes, "\n";
}
__END__
PS, where did you get the number 18501 from?
--
"I think not," said Descartes, and promptly disappeared.
------------------------------
Date: Mon, 03 Sep 2001 08:31:52 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: Godzilla DOS Perl Script Timer
Message-Id: <lo86ptgep81vqlse90m0vc62ofga4nd5br@4ax.com>
On Sun, 02 Sep 2001, "Godzilla!" <godzilla@stomp.stomp.tokyo> wrote:
>This is a low level DOS timer designed to measure
>the amount of time a Perl script takes to execute
>in milliseconds. It works quite well but there are
>some explicit instructions for use.
[...]
>My DOS timer is available here as a zip file. It is small:
>
>
>http://la.znet.com/~callgirl/timer.html
Source, please. Or do you really think people will run a binary of
dubious origin on their machines? Oh well, you may be right...
--
Thomas Baetzler - http://baetzler.de/ - Clan LoL - http://lavabackflips.de/
I am the "ILOVEGNU" signature virus. Just copy me to your signature.
This post was infected under the terms of the GNU General Public License.
------------------------------
Date: Mon, 03 Sep 2001 08:13:20 GMT
From: helgi@NOSPAMdecode.is (Helgi Briem)
Subject: Re: How to connect to Oracle DB using perl
Message-Id: <3b933b30.402337991@news.isholf.is>
On Thu, 30 Aug 2001 18:10:38 -0400, "Mr_Ocp"
<mr_ocp@yahoo.com> wrote:
>Hi Folks
>I am very new at perl, I am creating an intranet web site which would
>retrieve data from Oracle 8i Datbase. I have no clue how to configure
>connection to oracle using Perl5.
>
Use the DBI and DBD::Oracle modules.
When you have installed them use
perldoc -X DBD::Oracle to get examples of how
to use it.
Get them from CPAN (www.cpan.org) or use PPM
to install them if you have Activestate Perl.
Regards,
Helgi Briem
------------------------------
Date: Mon, 3 Sep 2001 16:06:40 +0930
From: "Matthew Frick" <mfrick@chariot.net.au>
Subject: Re: Installing perl-mysql interface
Message-Id: <3b93241f$1_3@news.chariot.net.au>
sounds to me like your dbi modules are not on the @inc. So I would make sure
that those modules are installed. If they are then I would see where they
have been installed to. If not on any of the inc paths then 1. you could try
copying them onto the inc or 2. you could push there directory path onto the
@inc.
hope this is some help.
"Peter Cassidy" <pcassidy@telocity.com> wrote in message
news:92Ak7.4406$ix.1423729@newsrump.sjc.telocity.net...
> I have Mandrake Linux 8.0 running quite nicely on a PIII 750 MHz system. I
> have installed perl (version 5.600-30mdk) and MySQL (version 3.23.39-1mdk)
> and am trying (unsuccessfully) to install perl-mysql interface. Attached
is
> the response I get when I try to do the install. I'm using the following
> command from the /root:
>
> perl -MCPAN -e shell
> install Bundle::CPAN
>
> The process starts off well but runs off the rails on page 3 at: Can't
> locate DBI/DBD.pm in @INC (@INC contains: /usr/lib/perl5/5.6.0/i386-linux
> /usr/lib/perl5/5.6.0 /usr/lib/perl5/site_perl/5.6.0/i386-linux
> /usr/lib/perl5/site_perl/5.6.0 /usr/lib/perl5/site_perl .) at Makefile.PL
> line 5.
> BEGIN failed--compilation aborted at Makefile.PL line 5.
>
> The process goes down hill from there.
>
> Any suggestions as to what's causing the problem are appreciated.
>
> Thanks,
> Peter Cassidy
>
>
>
>
------------------------------
Date: Mon, 3 Sep 2001 17:10:53 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Is there a better way of righting this...
Message-Id: <ooGk7.52$295.711@wa.nnrp.telstra.net>
"kdgjloiureo" <noone@none.com> wrote in message
news:vrk4ptkfaeeeq81f0t1tmf07pmpj405257@4ax.com...
> Right im fairly new to perl and im sure there must be a better way of
> righting the sub below any one have any ideas as to how to make this a
> bit more efficient.
>
<Large snippage>
Seems like a good case for a hash where adding new items and categories
simply involves making a matching directory, and then editing the hash.
BTW, for consistency, you should put Monitors in a directory called
monitors, unless that is an error.
sub print_record {
my %dirmap = (
'CD' => 'CD\'s',
'CDR' => 'CD RW\'s',
'Phone' => 'Phones',
'accessories' => 'Accessories',
'cable' => 'Cables',
'gfx' => 'Multimedia',
'HD' => 'Hard disk drives',
'Mainboard' => 'Mainboards',
'Memory' => 'Memory',
'Cases' => 'Cases',
'Software' => 'Software',
'notebooks' => 'Notebooks',
'Printers' => 'Printers',
'CPU' => 'Processors',
'controllers' => 'Controllers',
'Scanners' => 'Scanners',
'all' => 'All',
'monitors' => 'Monitors',
);
my $dir = $1 if $FORM{'select'} =~ m|.*/(.+)/$|; # extract the
directory name from the string
my $display = $dirmap{$dir}; # Set the display according to the key
from the hash
if ($dir eq 'monitors'){
$dir = ''; # Though I think it better to put Monitors in a dir
called monitors
}
elsif($dir eq ''){
#error condition - $dir not set - Need to handle this
intelligently...
}
else {
$dir = "../$dir/"; # add the other path information to the
directory
}
$price = $third_del / 1.175; # I don't like these globals here
$price2 = sprintf("%.2f", $price);
print_resualts_gen();
}
I chose to add the path information to the directory later rather than
extract it, because it makes the hash easier to edit later.
Wyzelli
--
($a,$b,$w,$t)=(' bottle',' of beer',' on the wall','Take one down, pass it
around');
$d='$_$a$s$b$w';$e='$_$a$s$b';sub d{$h=shift;$h=~s/\$(\w+)/${$1}/g;return$h}
sub
e{return(shift!=1)?'s':''}for(reverse(1..100)){$s=e($_);$f=d($d);$g=d($e);
$c.="$f\n$g\n$t\n";$_--;$s=e($_);$e=d($d);$c.="$e\n\n";}print"$c*hic*";
------------------------------
Date: Mon, 3 Sep 2001 01:17:39 -0400
From: "Whatevah" <webmaster@remove...this....whatevah.com>
Subject: performing commands through perl..
Message-Id: <9mv3pq$4c3ej$1@ID-94865.news.dfncis.de>
I need to perform a few commands using perl...
specifically, I need to use tar and gunzip...
I'm guessing that I have to use a certain module... but, which one?
I've never had my scripts interact with a server before... so, I'm sorry if
I've missed something easy
TIA
--
Jerry
www.whatevah.com
------------------------------
Date: Mon, 03 Sep 2001 08:40:50 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: performing commands through perl..
Message-Id: <5596ptgch1e03bdte4eeua6tu9gnl0ithk@4ax.com>
Hi,
On Mon, 3 Sep 2001, "Whatevah" <webmaster@whatevah.com> wrote:
>I need to perform a few commands using perl...
>
>specifically, I need to use tar and gunzip...
>
>I'm guessing that I have to use a certain module... but, which one?
Depending on what you want to do, it may just be easier to all those
two as externals - either using backticks, system() or open().
HTH,
--
Thomas Baetzler - http://baetzler.de/ - Clan LoL - http://lavabackflips.de/
I am the "ILOVEGNU" signature virus. Just copy me to your signature.
This post was infected under the terms of the GNU General Public License.
------------------------------
Date: 03 Sep 2001 12:39:02 +1000
From: Andrew Torda <Andrew.Torda@anu.edu.au>
Subject: perl extensions in C, special malloc libraries
Message-Id: <prk7zh9ewp.fsf@lasagne.anu.edu.au>
I have a perl extension written in C.
It malloc()s and free()'s all over the place.
I like to run my code with some of the malloc() checking
libraries.
Here is the problem.
My perl has been compiled to use the system malloc().
Under linux, I can link to a special library like electric
fence by adding
'LIBS' => ['-lefence'],
to the Makefile.PL. It works fine.
Under solaris, I can use solaris' cc, run in dbx and turn on
memory checking. This uses sun's fancy malloc/memory checking
library and all works fine.
Under solaris, I cannot persuade either cc or gcc to link in
an arbitrary library like electric fence. There are no errors,
but it seems to resolve references by finding malloc() in libc.
I have tried to persuade it to link to a static version
(libefence.a) and a dynamic version (libefence.so), but with
no luck.
Is there any recipe to use dynamic linking and to persuade
malloc() calls (at least from my perl extension) to use the
library I want ?
Thanks for any advice.
------------------------------
Date: Mon, 03 Sep 2001 01:10:12 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: Perl handcoded?
Message-Id: <ULAk7.301118$v5.30358076@news1.rdc1.ct.home.com>
Dave Tweed <dtweed@acm.org> wrote:
> Lijiv Khil wrote:
>> I was going through the sources of perl v 1.0. Is Perl written without
>> using any compiler construction tools like Lex and Yacc? I found that
>> all the transition tables etc were hand-coded in the sources.
> Even perl-1.000 (found at http://www.etla.org/retroperl/perl1/) has a
> perl.y file, so the answer is no. You might be looking at a distribution
> for a platform that didn't (yet) have a yacc or bison (DOS?), and so it
> included the pre-processed grammar.
All versions of perl, AFAIK, come with a preprocessed grammar. We don't
require a working yacc to build perl.
Dan
------------------------------
Date: Mon, 03 Sep 2001 04:26:04 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Problems with fixed-length random access databases.
Message-Id: <3B933E9C.7F3512E0@earthlink.net>
David Scarlett wrote:
>
> I'm trying to write a script here, which, each time it is run, should
> read from a file with a bunch of IP addresses and ping times and write
> do a database the IP address, port, sum of ping times so far and the
> number of times pinged. However, each time I run it, the file I'm
> saving the results in increases in size (10KB, 20KB, 30KB, 40KB, & so
> on).
>
> Ideally, the script searches linearly through the database, looking
> for records with the same IP & port, and if it finds one, it updates
> it. If it does not find one, it creates a new one at the end of the
> file. However, I think it may be always adding a new record to the end
> of the file rather than updating records.....
It sounds like what you really want is:
tie my(%lookup), DB_File => $filename;
my $key = pack "LS", $ip, $port;
if( exists $lookup{$key} ) {
my ($oldtimeval, $oldntimes) = unpack "fC", $lookup{$key};
$timeval += $oldtimeval; $ntimes += $oldntimes;
}
$lookup{$key} = pack "fC", $timeval, $ntimes;
untie %lookup;
Note that you no longer need to use fixed length strings. In
particular, you may want to replace the "C" template with a "w"
template, so it can be as large as you want, not limited to 0..255.
--
"I think not," said Descartes, and promptly disappeared.
------------------------------
Date: Mon, 03 Sep 2001 03:55:52 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: random link from web page
Message-Id: <3B933788.38EF4540@earthlink.net>
confused wrote:
>
> ok, i am using the code at the bottom of this message to get links
> from a web page. How do i get it to return only 1 random link from the
> page so every time you goto the cgi page, it will show a different
> link ?
>
> #!/usr/bin/perl -w
>
> use strict;
> use HTML::LinkExtor;
> use LWP::Simple;
>
> my %seen;
> my $url = "http://www.yahoo.com";
> my $parser = HTML::LinkExtor->new(undef, $url);
> $parser->parse(get($url))->eof;
> my @links = $parser->links;
> foreach my $linkarray (@links) {
Why are the above two things on seperate lines? The only place that the
result of $parser->links is used is the foreach... you don't need the
results after that, so don't store them.
foreach my $linkarray ( $parser->links ) {
> my @element = @$linkarray;
> my $elt_type = shift @element;
> while (@element) {
> my ($attr_name, $attr_value) = splice(@element, 0, 2);
> $seen{$attr_value}++;
> }
Why get parts you don't need? Replace the entire insides of the for
loop with:
for( my $i = 2; $i < @$linkarray; $i += 2 ) {
$seen{ $linkarray->[$i] }++;
}
> }
Here's another way of doing the foreach loop:
@seen{map {
my $la = $_;
map { $la->[$_ & ~1] } 2 .. $#$la;
} $parser->links} = ();
I wouldn't suggest using it, but you might have been considering it.
This also works:
foreach my $linkarray ( $parser->links ) {
@seen{ map { $linkarray->[$_ & ~1] } 2 .. $#$linkarray } = ();
}
> print "Content-type: text/html\n\n";
Are you sure that this is what you want to be printing?
I would think you would want to *go to* the link you'd found.
This would be done by printing a Location header instead of a
Content-type header.
> for (sort keys %seen) { print $_, "\n" };
To get one random link from %seen, you can do either of:
print ((keys %seen)[rand(scalar keys %seen)], "\n");
or:
my $randval;
for( my ($idx,$iter)=(1); $iter = each %seen; ++$idx ) {
$randval = $iter if( rand() < 1/$idx );
}
print $randval, "\n";
Both work equally well. The first uses more memory, but is faster.
The second is slower, but uses almost no memory. Which one you prefer
depends on your needs.
Here's all the things I suggested put together.
#!/usr/bin/perl -w
use strict;
use HTML::LinkExtor;
use LWP::Simple;
my $url = "http://www.yahoo.com";
my $parser = HTML::LinkExtor->new(undef, $url);
$parser->parse(get($url))->eof;
my %seen;
foreach my $linkarray ($parser->links) {
for( my $i = 2; $i < @$linkarray; $i += 2 ) {
$seen{ $linkarray->[$i] } = 1;
}
}
print "Location: ";
print +(keys %seen)[rand(scalar keys %seen)];
print "\n\n";
__END__
--
"I think not," said Descartes, and promptly disappeared.
------------------------------
Date: 3 Sep 2001 01:53:02 -0700
From: demerphq@hotmail.com (Yves Orton)
Subject: Re: Recommendations for a PERL editor
Message-Id: <74f348f7.0109030053.5041ede6@posting.google.com>
"sabin" <sabin@cornhusker.net> wrote in message news:<3b928912_8@Usenet.com>...
> > UltraEdit adds features like syntax highlighting (which IMO
> > is a must-have feature for editing Perl code), but it is
> > shareware. It feels like a regular Windows app. I don't
> > remember how much the registration fee is.
>
> Its $30. I've used it. Its 'ok' but seems to crash on me about every hour
> or so.
Thats weird Ive never experienced that and I use it all the time.
Maybe its just W9x thats the problem? That does have a habit of
BSODing you at the worst moment.
Yves
------------------------------
Date: 2 Sep 2001 18:36:35 -0700
From: greenseaweed@aol.com (Mr. Green)
Subject: Re: registration worries
Message-Id: <5370f8aa.0109021736.71b199ab@posting.google.com>
gnari <gnarinn@hotmail.com> wrote in message news:<999284404.348872086033225.gnarinn@hotmail.com>...
> In article <5370f8aa.0108301506.a953820@posting.google.com>,
> Mr. Green <greenseaweed@aol.com> wrote:
>
> (snipped code to produce unique 4 digit number to be used as
> file name presumablu under cgi)
>
> in addition to other remarks you have received, let me add
> that this strategy to produce unique filenames under concurrent
> environment is unsafe.
>
> consider these points:
>
> as the number of allocated files approaches 9000, it will
> take more and more time to find a unused number. at last your
> program will hang indefinitely when all the bins have been filled.
>
> when your server receives 2 request simultaneously, there is
> a small probability that both will be allocated the same number.
>
> this probability may be small, but why take chances, when a different
> approach can easily remove it
Agreed. I was worried about the same things. I found that there are
many, many different ways of doing this (POSIX, IO::File, etc). It
looks like just using the process ID will work best for my situation.
(That should eliminate the small possiblity of allocating the same
filename when my program receives 2 requests simultaneously.)
$Path = '/local/etc/httpd/htdocs/blah/registration';
$name = random_name();
sub random_name {
my $rand1 = $$;
do {
$rand1++;
} while ( -e "$Path/$rand1" );
return $rand1;
}
open (FILEWRITE, ">$name") || die "Couldn't open $name for writing:
$!";
.
.
.
Hmmm... the $rand1++ part really bothers me. Let's say I receive 2
requests simultaneously and one has a PID of 500 and the other, 501.
And 500 is already a filename (in $Path), but 501 is not. Couldn't
this unlikely scenario lead to problems?
------------------------------
Date: Mon, 03 Sep 2001 02:19:31 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: sysread problem on socket
Message-Id: <3B9320F3.A73220A0@earthlink.net>
Alex Hart wrote:
>
> Benjamin Goldberg wrote:
>
> > Alex Hart wrote:
[snip]
> > > my $first_response;
> > > sysread(POP, $first_response, 1024);
> >
> > There's no garuntee that this will contain the entire first
> > response, only that it will contain a nonzero amount of data [unless
> > we've hit eof, in which case it will be zero bytes].
>
> But this does work, at least 99.9% of the time
So that means that 99.9% of the servers buffer their responses so that
each is sent in a single call to write() [or syswrite, or whatever].
If you want your code to handle 100% of the servers which exist, then
this bit off code which falsely assumes you can always get the whole
response in a single call to sysread just won't cut it.
Oh, and if you want reading responses to be able to time out, then you
need to do one of the following:
Set a timeout on the socket. This isn't portable... it doesn't work on
most perl code.
Use alarm. Note that alarm is not implemented on windows.
Use select or IO::Select. Note that if you use one of these two, then
you can not use read() or <POP>, but must use sysread. This means that
you may need to repeatedly loop until you have an entire response [if
you used <POP>, then you would be guaranteed to get a entire response].
Here's an example script which does what yours is intended to do, but
with a timeout. Also without alot of the error checking it should do,
but this is just an example.
#!/usr/bin/perl -w
use strict;
use Socket; use IO::Select;
use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK);
my( $server, $user, $pass ) = @ARGV;
socket(POP, AF_INET, SOCK_STREAM, (getprotobyname('tcp'))[2]);
select((select(POP),$|=1)[0]);
$select = IO::Select->new(\*POP);
fcntl(POP, F_SETFL, fcntl(POP, F_GETFL) | O_NONBLOCK);
connect(POP, sockaddr_in (110, inet_aton($server)));
unless( () = $select->can_read( 2 ) ) {
die "Could not connect to POP server within 2 seconds\n";
}
fcntl(POP, F_SETFL, fcntl(POP, F_GETFL) & ~O_NONBLOCK);
sub getresponse {
my $resp = "";
do {
die "Could not get response within 2 seconds\n";
unless( () = $select->can_read( 2 ) );
sysread( POP, $resp, 1024, length $resp );
} while( index( $resp, "\015\012" ) != -1 );
$resp =~ s/\015\012/\n/g;
print "server: $resp";
die "server didn't respond properly.\n"
unless $resp =~ /^\+OK/;
}
getresponse;
foreach my $cmd ("USER $user","PASS $pass",qw(STAT QUIT)) {
print "client: $cmd\n";
print POP "$cmd\015\012";
getresponse;
}
__END__
--
"I think not," said Descartes, and promptly disappeared.
------------------------------
Date: Mon, 3 Sep 2001 09:22:51 +0200
From: "Jonas Nilsson" <jonni@ifm.liu.nospam.se>
Subject: Re: Using less memory for hashes
Message-Id: <9mvb3j$7ej$1@newsy.ifm.liu.se>
"Tintin" <somewhere@in.paradise.net> wrote in message
news:08fk7.6$4y3.206907@news.interact.net.au...
| I'm interested in various techniques to reduce memory usage using hashes.
| Typcially, I'm talking about where a large file (say >1Gb) is read into a
| hash and then sorted.
|
It would help us to help you, if you supplied i small portion of the file
you want to have sorted and in which way you want to have it sorted.
/jN
------------------------------
Date: Mon, 03 Sep 2001 05:29:20 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Using less memory for hashes
Message-Id: <3B934D70.F0273EAD@earthlink.net>
Tintin wrote:
>
> I'm interested in various techniques to reduce memory usage using
> hashes. Typcially, I'm talking about where a large file (say >1Gb) is
> read into a hash and then sorted.
>
> I read the FAQ about reducing memory usage, but is mainly talks about
> arrays. One method I was thinking of using is a tied DBM hash (is
> that the right term?). I'm not so worried about the slow down in
> performance, more about getting a file processed without the server
> swapping like crazy.
Hmm, sounds like you want to use DB_File using the BTREE format.
This untested code reads in from FILE, splits on whitespace, then prints
out all the words in alphabetic order.
my $filename = "/tmp/tmpfile.$$." . time . "." . rand;
tie my (%foo), DB_File => $filename, ...., $DB_BTREE;
$foo{$_} = '' if !exists $foo{$_} foreach( split ) while( <FILE> );
print $_, "\n" while defined $_ = each %foo;
untie %foo; unlink $filename;
--
"I think not," said Descartes, and promptly disappeared.
------------------------------
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 1683
***************************************