[16234] in Perl-Users-Digest
Perl-Users Digest, Issue: 3646 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 13 00:05:45 2000
Date: Wed, 12 Jul 2000 21:05:11 -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: <963461111-v9-i3646@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 12 Jul 2000 Volume: 9 Number: 3646
Today's topics:
Re: ATTENTION PERL MACHOES!!!!!!!!!!!!!!!!!!! (Randal L. Schwartz)
Re: ATTENTION PERL MACHOES!!!!!!!!!!!!!!!!!!! (Young H Lee)
Re: ATTENTION PERL MACHOES!!!!!!!!!!!!!!!!!!! (Young H Lee)
autoflushing not as good as closing? <bob@bob-n.com>
Bottleneck? Array or writing - neither? <esmithNOesSPAM@exeter.com.invalid>
Re: Bottleneck? Array or writing - neither? (Keith Calvert Ivey)
Re: Bottleneck? Array or writing - neither? <esmithNOesSPAM@exeter.com.invalid>
Re: Bottleneck? Array or writing - neither? <esmithNOesSPAM@exeter.com.invalid>
Re: Bottleneck? Array or writing - neither? <nnickee@nnickee.com>
Re: command line input <taboo@doofa.net>
Convert "\xAB\xCD" into number 43981 <abuse@localhost>
Re: Email Attachments in Perl (no modules) (David Efflandt)
Re: fork function (jason)
Re: Hash vs. Array memory usage (Peter McMorran)
how to capture the message return from the system() <lucas@cplhk.com>
Re: how to capture the message return from the system() (Decklin Foster)
HOW TO FTP A FILE IN PERL SCRIPT <nurain@singnet.com.sg>
looking for ntp example please <robert@chalmers.com.au>
Re: metrics <randy@theory.uwinnipeg.ca>
Re: New to perl, need help (Michal Jaegermann)
Newbies cry for help <ecco64@chello.nl>
Re: Newbies cry for help <taboo@doofa.net>
Re: Newbies cry for help (Craig Berry)
Re: Newbies cry for help <ecco64@chello.nl>
NNTP Newsgroup script problem! <nospam@one.net.au>
Perl new users:about locat the string in file? <chaptera@hotmail.com>
Re: Perl... the split function (Peter McMorran)
Re: PRINTing " "" " <peter.sundstrom@eds.com>
Re: Problems with reading and printing file! <tony_curtis32@yahoo.com>
Re: Problems with reading and printing file! <bwalton@rochester.rr.com>
Re: regex question <rrindels@arkansas.net>
Re: using %ENV with CGI <tony_curtis32@yahoo.com>
Re: using %ENV with CGI <trent.mankelow@unisys.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 12 Jul 2000 18:19:17 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: ATTENTION PERL MACHOES!!!!!!!!!!!!!!!!!!!
Message-Id: <m1snteq12i.fsf@halfdome.holdit.com>
>>>>> "Craig" == Craig Berry <cberry@cinenet.net> writes:
Craig> Jeff H (jeffahill@lucent.com) wrote:
Craig> : But the books that Randall
Craig> That's "Randal". I believe his middle name is "=~ tr/a-z//s".
Just as long as you don't sort that first. :)
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: 13 Jul 2000 01:53:06 GMT
From: yhlee@mail.med.upenn.edu (Young H Lee)
Subject: Re: ATTENTION PERL MACHOES!!!!!!!!!!!!!!!!!!!
Message-Id: <8kj7e2$slo$1@netnews.upenn.edu>
: on the contrary, I've found that on the few occasions when I've been referred to
: the *correct* perldoc and given one or two pushes towards wherein those docs to
: look for my answers, I've had over time, less and less trouble figuring out what
: I needed to do on my own (like complex dereferencing of hashes of hashes of
: lists, for example)
I dont disagree but when you're asking about say command X, i think it is
a reasonable assumption that the poster read the perldoc on X
: Generally I've found that when you HAVE read the docs enough to post an
: INTELLIGENT question instead of begging for everyone to solve problems
: willy-nilly, you get more constructive replies.
While I dont disagree, whether or not something is an "intelligent
question" is often subjective. I dont think i ever defended anyone
'begging to have problems solved' at least for that reason.
: This is not specific to the perl community either, but is endemic to usenet in
: general :D
--
-----
Young H. Lee
"Never try to teach a pig to sing. It wastes your time and annoys the pig."
------------------------------
Date: 13 Jul 2000 01:55:59 GMT
From: yhlee@mail.med.upenn.edu (Young H Lee)
Subject: Re: ATTENTION PERL MACHOES!!!!!!!!!!!!!!!!!!!
Message-Id: <8kj7jf$slo$2@netnews.upenn.edu>
: But the original poster's point was that Our Hero's command of English
: seemed to be getting worse and worse with each post, whereas most
: people's command of a second language *improves* the more they use it.
Maybe she's emotionally unstable. ;)
It could be though that when put up to the task, those with less practice
perform at a level less than his or her true ability (though it doesnt seem
to be the case here).
: P.S. "HaXor" = "kewl" spelling of "hacker."
ah ok, figured it was something like that..
--
-----
Young H. Lee
"Never try to teach a pig to sing. It wastes your time and annoys the pig."
------------------------------
Date: Wed, 12 Jul 2000 21:41:15 -0500
From: Bob Niederman <bob@bob-n.com>
Subject: autoflushing not as good as closing?
Message-Id: <396D2C4B.BFC8A8C6@bob-n.com>
I got tired of nslookup not having readline support. (I first looked at
the source code for nslookup to see if I could hack this. I have NO
idea what is going on when they read a command. It appear purposefully
obfuscated to me, but then I'm not much of a c programmer.
So I fugred, OK, IPC::Open3 + Term::ReadLine should do it.
Here's what I wrote:
#!/usr/bin/perl -w
use strict;
use IPC::Open3;
use FileHandle;
use Term::ReadLine;
my $term = new Term::ReadLine 'readline support';
STDERR->autoflush(1);
STDOUT->autoflush(1);
my($WTR, $RDR) = (FileHandle->new, FileHandle->new);
my $pid = open3($WTR, $RDR, $RDR, "$ARGV[0]");
die "open3 failed" unless $pid;
autoflush $WTR 1;
my ($rout, $rin, $prompt) = ('', '', '');
vec($rin,fileno($RDR),1) = 1;
$SIG{ALRM} = sub {
my $nfound = select($rout=$rin, undef, undef, 0);
if ( $nfound ) {
my ( $nread, $read_stuff);
$nread = sysread $RDR, $read_stuff, 2048;
if ( defined $nread and $nread ) {
print $read_stuff;
}
}
alarm(1);
return;
};
alarm(1);
while ( defined ( my $input = $term->readline($prompt) ) ) {
$input .= "\n";
syswrite $WTR, $input;
# close $WTR;
}
close $WTR;
close $RDR;
# END
this is a file called rl.pl, so its use is:
rl.pl nslookup
except it doesn't work. The initial output of nslookup starting up
appears, but nothing happens after inputting a command. If the 'close
$WTR' is uncommneted inside the while loop, however, then the output of
the first command IS returned as expected. Of course, all subsequent
commands fail due to writing on a closed filehandle.
The program works as written if used with cat (rl.pl cat).
I don't get it. Why isn't autoflushing $WTR (I've tried this with print
or using syswrite, which also does no buffering) as good as closing the
file?
Almost forgot:
# perl -v
This is perl, version 5.005_03 built for i386-linux
on redhat linux 6.0
--
- Bob Niederman http://bob-n.com
Fight UCITA! http://www.4cite.org, http://bob-n.com/ucita
------------------------------
Date: Wed, 12 Jul 2000 18:27:25 -0700
From: Eric <esmithNOesSPAM@exeter.com.invalid>
Subject: Bottleneck? Array or writing - neither?
Message-Id: <01800c00.326741f9@usw-ex0102-016.remarq.com>
**Sorry if this came through twice - I tried remarq's "posting
from e-mail" and it didn't show up all day, so now I'll try via
this little form**
Good day! I am new to perl and absolutely love it - I'm not sure
the last time I've had so much fun - and wow is this fast!
My question that the subject hints at is this:
I have a program that is doing several things, and I tossed in
timers that print to the screen to see where the bottleneck is
since it will sit here nicely and use lots of processor
otherwise without me knowing what stage it has hit.
The first stage it pulls in text from a file (2861742 chars,
527190 words, and 54114 lines) and tosses that into an array.
That works nicely and is not the bottleneck (0.31 CPU seconds on
a dual processor PIII 600 with 256 megs ram - although if you
ask me it is only using one processor - I think NT is bad about
that and forces programs to deal with it on their own - there's
a side question - can you control threads or processors via
Perl - sorry, I'm new).
Next it does a for loop through the array and strips out some
characters (nonword chars and numbers) - this takes 1.66 CPU
seconds - still not the bottleneck.
Then it joins that array into a string - nice and fast at 0.09
CPU s.
After that it goes through from the very end and takes every 4th
character and tosses that into a spot in the array, then chops
of the last letter and continues through that. I thought that's
be the bottleneck - but that is still fast at 8.48 CPU seconds.
Then I sort the array with a simple $a cmp $b and that weighs in
at the heavy 22.44 CPU secs.
And last, but certianly not least, it sits there for over an
hour now where it does many a thing (and this is where I'd love
feedback on ways to speed this up - the rest might not be
perfect, but it is very reasonably fast considering how much it
is going through) - any suggestions (feel free to tell me how
bad my code is - I'm still learning and love feedback - esp the
kind that makes my code faster) would be very much appreciated!
#I'm reading up on hashes now to see if I can use them to make
this faster
my $oldWord = '';
for (@bigArrayOWords)
{
my $testWord = $_;
if ($testWord ne $oldWord)
{
#print $_, "\n";
my $count = grep $_ eq $testWord =>
@bigArrayOWords;
my $step=0;
my $condition=0;
while($condition <= $count)
{
$condition = int(2**$step);
$step++;
}
my $score = $step-1;
if ($score<=0)
{
$score = 0;
}
#output to file
open (TETRAGRAPHS, ">>$tetragraphs") or
die "cannot open TETRAGRAPHS: $!";
print TETRAGRAPHS "$testWord:$count:$score
\n";#ouputs WORD:COUNT:SCORE
close TETRAGRAPHS or die "cannot close
TETRAGRAPHS: $!";
#output to screen
#print "$testWord:$count:$score";#ouputs
WORD:FREQUENCY:SCORE
#print "\n";
}
$oldWord = $testWord;
}
-----------------------------------------------------------
Got questions? Get answers over the phone at Keen.com.
Up to 100 minutes free!
http://www.keen.com
------------------------------
Date: Thu, 13 Jul 2000 02:32:28 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: Bottleneck? Array or writing - neither?
Message-Id: <396d2347.8096292@nntp.idsonline.com>
Eric <esmithNOesSPAM@exeter.com.invalid> wrote:
>#I'm reading up on hashes now to see if I can use them to make
>this faster
That's definitely what you should be doing. The words "count"
and "unique" should trigger thoughts of hashes.
>my $oldWord = '';
>for (@bigArrayOWords)
>{
> my $testWord = $_;
> if ($testWord ne $oldWord)
When you have a conditional that covers the whole last part of a
loop, it's nicer to reverse the sense of the test and use next:
next if $testWord eq $oldWord;
That way you can avoid indenting the whole rest of the loop.
> {
> #print $_, "\n";
> my $count = grep $_ eq $testWord =>
>@bigArrayOWords;
This is where a lot of your time goes, I'd guess. For every
unique entry in the array, you're looping through the array
again (with grep).
There are some weird things below, but they're probably not
slowing you down much:
> my $step=0;
> my $condition=0;
> while($condition <= $count)
> {
> $condition = int(2**$step);
> $step++;
> }
> my $score = $step-1;
> if ($score<=0)
> {
> $score = 0;
> }
How could $score ever be less than 0? $count is always at least
1; $step starts at 0; so you always go through the while loop at
least once, and $step is always at least 1. And if $score is
equal to 0, there's no need to set it equal to 0.
And what's the int() for? $step is an integer, so 2 ** $step
will be an integer.
Anyway, this whole section can be replaced with one line:
my $score = int(log($count)/log(2)) + 1;
> #output to file
> open (TETRAGRAPHS, ">>$tetragraphs") or
>die "cannot open TETRAGRAPHS: $!";
>
> print TETRAGRAPHS "$testWord:$count:$score
>\n";#ouputs WORD:COUNT:SCORE
>
> close TETRAGRAPHS or die "cannot close
>TETRAGRAPHS: $!";
Here's another big slowdown. You're opening and closing the
file each time through the loop. Open it before the loop and
close it after.
> #output to screen
> #print "$testWord:$count:$score";#ouputs
>WORD:FREQUENCY:SCORE
>
> #print "\n";
> }
> $oldWord = $testWord;
>}
You need to use a hash. You can probably construct it instead
of the array, but I don't know how you're constructing the
array. You can construct the hash from the array (which you
don't need to sort first) like this:
my %count;
++$count{$_} for @bigArrayOWords;
And then just do this instead of everything you've written
above:
open(T, ">>$tetragraphs")
or die "cannot open $tetragraphs: $!";
for (sort keys %count) {
my $score = int(log($count{$_})/log(2)) + 1;
print T "$_:$count{$_}:$score\n";
}
close T or die "cannot close $tetragraphs: $!";
--
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 80,000 Newsgroups - 16 Different Servers! =-----
------------------------------
Date: Wed, 12 Jul 2000 19:48:01 -0700
From: Eric <esmithNOesSPAM@exeter.com.invalid>
Subject: Re: Bottleneck? Array or writing - neither?
Message-Id: <21b6a00c.476df005@usw-ex0102-016.remarq.com>
Thanks for the quick reply Keith - hopefully I can fix this
tonight and run it on
my computer at home (I think it is still running at work right
now)!
>>#I'm reading up on hashes now to see if I can use them to make
this faster
>That's definitely what you should be doing. The words "count"
>and "unique" should trigger thoughts of hashes.
Yeah, I'm a pretty big newbie - not a comp sci guy (I'm sure you
can tell
by the code errs) - but I had just now written up a test on a
small amount
of text, now I'll write it into this big one.
>>my $oldWord = '';
>>for (@bigArrayOWords)
>>{
>>my $testWord = $_;
>>if ($testWord ne $oldWord)
>When you have a conditional that covers the whole last part of
a loop, it's
>nicer to reverse the sense of the test and use next:
>
>next if $testWord eq $oldWord;
>
>That way you can avoid indenting the whole rest of the loop.
awesome! thanks - I don't know a lot fo this stuff that is
probably common
sense to you guys - I'm learning though and having a blast!
>>{
>>#print $_, "\n";
>>my $count = grep $_ eq $testWord =>
>>@bigArrayOWords;
>This is where a lot of your time goes, I'd guess. For every
unique entry in the
>array, you're looping through the array again (with grep).
ouch! I grabbed that code off of someone's post in a newsgroup
(likely
this one) and I didn't really think it through since it seemed
fast enough in tests
(obviously much smaller tests)
>There are some weird things below, but they're probably not
slowing you
>down much:
these are scoring tests
>>my $step=0;
>>my $condition=0;
>>while($condition <= $count)
>>{
>>$condition = int(2**$step);
>>$step++;
>>}
>>my $score = $step-1;
>>if ($score<=0)
>>{
>>$score = 0;
>>}
>How could $score ever be less than 0? $count is always at least
1; $step starts
>at 0; so you always go through the while loop at least once,
and $step is always
>at least 1. And if $score is equal to 0, there's no need to set
it equal to 0.
yeah, I guess that was/is dumb. that part was written late at
night and obviously snuck
right by me - no excuse as to why I didn't notice it later on
though - Thanks!
>Anyway, this whole section can be replaced with one line:
>
>my $score = int(log($count)/log(2)) + 1;
great! - I love the one line condensers
>>#output to file
>>open (TETRAGRAPHS, ">>$tetragraphs") or die "cannot open
TETRAGRAPHS: $!";
>>print TETRAGRAPHS "$testWord:$count:$score
>>\n";#ouputs WORD:COUNT:SCORE
>>close TETRAGRAPHS or die "cannot close
>>TETRAGRAPHS: $!";
>Here's another big slowdown. You're opening and closing the
file each time through
>the loop. Open it before the loop and close it after.
hmm, yeah, before I had it as you say and on tests this seemed
to speed it up - obviously
I'm not testing it hard enough prior to the real thing - lesson
learned.
>You need to use a hash. You can probably construct it instead
of the array, but I don't
>know how you're constructing the array. You can construct the
hash from the array
>(which you don't need to sort first) like this:
I'll look into it - the array is huge (over 1,792,911), it looks
like I don't need it though
Thanks so much again for all of your help! I look forward to
seeing more responses -
great way to learn to have someone review your code.
-Eric
-----------------------------------------------------------
Got questions? Get answers over the phone at Keen.com.
Up to 100 minutes free!
http://www.keen.com
------------------------------
Date: Wed, 12 Jul 2000 20:22:42 -0700
From: Eric <esmithNOesSPAM@exeter.com.invalid>
Subject: Re: Bottleneck? Array or writing - neither?
Message-Id: <3aaa0b0b.507a377e@usw-ex0102-016.remarq.com>
YES!!!
Thanks again Keith!
Even on my slower machine here at home, it got through the whole
thing amazingly fast (it created 50,000+ lines of text in 8.67
CPU secs - the same task was going to take my other cruddy code
all day - literally!).
This gives me much more confidence for the second stage of my
program.
Wow, hashes are cool.
-Eric
-----------------------------------------------------------
Got questions? Get answers over the phone at Keen.com.
Up to 100 minutes free!
http://www.keen.com
------------------------------
Date: Wed, 12 Jul 2000 22:50:33 -0500
From: Nnickee <nnickee@nnickee.com>
Subject: Re: Bottleneck? Array or writing - neither?
Message-Id: <37CEAB02BFD2C17B.3E9B32B6489D3AAF.D7CA42516511EBF4@lp.airnews.net>
On Wed, 12 Jul 2000 19:48:01 -0700, someone claiming to be Eric
<esmithNOesSPAM@exeter.com.invalid> said:
[ lots of snips ]
>Thanks for the quick reply Keith - hopefully I can fix this
>tonight and run it on
>my computer at home (I think it is still running at work right
>now)!
Uh oh...
>>>#output to file
>>>open (TETRAGRAPHS, ">>$tetragraphs") or die "cannot open
>TETRAGRAPHS: $!";
>>>print TETRAGRAPHS "$testWord:$count:$score
>>>\n";#ouputs WORD:COUNT:SCORE
>>>close TETRAGRAPHS or die "cannot close
>>>TETRAGRAPHS: $!";
I had something similar to this happen to me a while back... what
prompted the "Uh oh" was realizing quite a few months after the fact
that the reason my script was taking sooooo long to write to the file
was because the script had flipped out [read: "I did something really
stupid"] and the resulting file which should have been around 200k
when finished... was <gulp> 1.2 gigs.
You might want to check the size of your $tetragraphs file when you
get to work tomorrow, just to be on the safe side :)
Nnickee
------------------------------
Date: 13 Jul 2000 01:49:41 +1000
From: "Kiel Stirling " <taboo@doofa.net>
Subject: Re: command line input
Message-Id: <396c9395$1_3@nexus.comcen.com.au>
nvp@spamnothanks.speakeasy.org (NP) wrote:
>On 12 Jul 2000 23:39:54 GMT, BFisher244 <bfisher244@aol.com> wrote:>: i am implementing a function and am trying to allow flags.
>: How can I signal that there is a flag for all input?
>
>Why not use the Getopt modules: Getopt::Std or Getopt::Long?
>
>--
>Nate
>
Why not use @ARGV?
If you run your program with options ie,
$ program -v -s -p
$ARGV[0] will eq -v
$ARGV[1] will eq -s and so on.
------------------------------
Date: Thu, 13 Jul 2000 10:43:38 +0800
From: "multiplexor" <abuse@localhost>
Subject: Convert "\xAB\xCD" into number 43981
Message-Id: <8kj9u6$dvr92@imsp212.netvigator.com>
I have a string, say, "\xAB\xCD\xEF\xEF", and I want to convert it into a
number. That is, treat the string as bytes. What is the simplest way to do
that? I tried the followings but the result is strange to me:
print join('', unpack('L*', "\xAB\xCD")), "\n"; #prints nothing
print join('', unpack('L*', "\xAB\xCD\EF")), "\n"; #prints nothing
print join('', unpack('L*', "\xAB\xCD\xEF\xEF")), "\n"; #prints
4025470379
print join('', unpack('L*', "\xFF\xFB\x90\x74")), "\n"; #prints
1955658751 < 4025470379 !?
Thanks.
------------------------------
Date: 13 Jul 2000 02:28:07 GMT
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Email Attachments in Perl (no modules)
Message-Id: <slrn8mqa95.6h8.efflandt@efflandt.xnet.com>
On Wed, 12 Jul 2000, Dubreu Mathieu <mdubreu@atos-group.com> wrote:
>Is there any way to attach a file to a mail only with the SMTP package ?
>I have encoded a file in Base64, but the SMTP package put the file in
>the body of my mail.
If you can't figure out how to put 'Lite.pm' into a dir called 'MIME' and
point to the parent dir of MIME with: use lib '/sys_path_to/mymodules';
why don't you look at Lite.pm for clues as to how it is done?
Nobody is going to totally explain the inner workings of smtp in a news
post when there is already a module that is so simple to install, or use
as an example.
--
David Efflandt efflandt@xnet.com http://www.de-srv.com/
http://www.autox.chicago.il.us/ http://www.berniesfloral.net/
http://hammer.prohosting.com/~cgi-wiz/ http://cgi-help.virtualave.net/
------------------------------
Date: Thu, 13 Jul 2000 01:13:27 GMT
From: elephant@squirrelgroup.com (jason)
Subject: Re: fork function
Message-Id: <MPG.13d7b5046977c27a98968d@news>
Gregory Vainberg wrote ..
>I am writting a perl code in a windows environment. I dont have a unix
>machine.
>
>I always get the message, when I try to use fork that this function is not
>supported, is that becuase I am using windows, if not what is the problem
>and if so is there a windows counterpart to this function.
read the "BUGS AND CAVEATS" section of the documentation
perldoc perlwin32
regarding options .. there is experimental threading support available
(requires a recompile of Perl - or I think ActiveState might have a
threaded Perl binary for 5.6)
or there is Win32::Process which might suit your needs .. it's a
standard module in the ActiveState distribution
--
jason -- elephant@squirrelgroup.com --
------------------------------
Date: Thu, 13 Jul 2000 01:58:33 GMT
From: mcmorran@visi.net (Peter McMorran)
Subject: Re: Hash vs. Array memory usage
Message-Id: <396d2244$2$zpzbeena$mr2ice@news.visi.net>
In <MPG.13d4051e67f9c08898abb2@nntp.hpl.hp.com>, on 07/10/00
at 05:07 PM, Larry Rosler <lr@hpl.hp.com> said:
>[Removed alt.perl.]
>In article <3Tra5.15672$DL.66198@nnrp1.none.net> on Tue, 11 Jul
>2000 00:10:43 +0200, nicolas <webmaster@archiTacTic.com>
>says... >
>> Michael Carman <mjcarman@home.com> a crit dans le message :
>> 396A1828.D5CE08CA@home.com...
>> > when
>> > processing a file it is much more memory-friendly to parse it line by
>> > line instead of slurping the whole thing into memory first.
>> >
>> That's what I started doing, but I have to compare an Array to another
>> Array. In other words, I have an Array which I want to compare to a data
>> file to see if elements are already there. The only thing I found was to
>> "slurp" the whole database into a variable (the @MyBigVar array) and then
>> comparing my other array to it to eliminate doubles.
>> So if you tell me that an array is better for memory, I'll keep that.
>Memory isn't the issue here. Performance is the issue.
>To see what to do, read perlfaq4: "How do I compute the
>difference of two arrays? How do I compute the intersection of
>two arrays?" and several nearby FAQs. You will want to use a
>hash, because using an array leads to quadratic performance
>(i.e., very slow for large arrays).
Yes. However, _if_ the two files are already sorted in the same
order, you could implement a merge algorithm, keeping both files
open and reading records from whichever file is behind in the
order. When both files match, you will be looking at the matching
record from each file. Then, there is no need for any array in
memory. Otherwise, a hash is the only way to go, since searching
an array linearly for each record from the second file will take
forever.
Cheers,
Peter
--
-----------------------------------------------------------
mcmorran@visi.net (Peter McMorran)
-----------------------------------------------------------
------------------------------
Date: Thu, 13 Jul 2000 10:00:53 +0800
From: "Lucas Gump" <lucas@cplhk.com>
Subject: how to capture the message return from the system()
Message-Id: <8kj7sq$eov1@imsp212.netvigator.com>
As title.
Thanks
------------------------------
Date: 13 Jul 2000 03:11:06 GMT
From: decklin@red-bean.com (Decklin Foster)
Subject: Re: how to capture the message return from the system()
Message-Id: <8kjc09$2m0bl$1@ID-10059.news.cis.dfn.de>
Lucas Gump <lucas@cplhk.com> writes:
> As title.
And that's how you do it.
> Thanks
You're welcome.
--
There is no TRUTH. There is no REALITY. There is no CONSISTENCY. There
are no ABSOLUTE STATEMENTS. I'm very probably wrong. -- BSD fortune(6)
------------------------------
Date: Thu, 13 Jul 2000 11:45:16 +0800
From: "lova" <nurain@singnet.com.sg>
Subject: HOW TO FTP A FILE IN PERL SCRIPT
Message-Id: <8kjdot$gt7$1@violet.singnet.com.sg>
Hi
I am currently trying to write a script to FTP some files over to another
machine and capture the output of the FTP command.
How do I do this?
Help needed urgently.
Thanks
Regards
Nurain - Lova
------------------------------
Date: Thu, 13 Jul 2000 13:32:59 +1000
From: "Robert Chalmers" <robert@chalmers.com.au>
Subject: looking for ntp example please
Message-Id: <TIab5.40$BW3.4284@nsw.nnrp.telstra.net>
I'm looking for examples of using ntp to fetch the time from servers. Or
indeed is this possible?
thanks
Bob
------------------------------
Date: Wed, 12 Jul 2000 21:20:47 -0500
From: "Randy Kobes" <randy@theory.uwinnipeg.ca>
Subject: Re: metrics
Message-Id: <8kj96t$j4$1@canopus.cc.umanitoba.ca>
Nadim Khemir <nkh@cpen.com> wrote in
message news:396cadaa.0@d2o68.telia.com...
> Can someone point me to some metric scripts ?
If you mean conversions between the imperial
and si systems, look at the Math::Units module;
see, for example,
http://theoryx5.uwinnipeg.ca/CPAN/data/Math-Units/Units.html
for a synopsis. Alternatively, check out the
Convert::Units::* modules. Or do you mean to
extract info from TeX font metric files? Then the
Font::TFM module may be useful. Or Adobe
font metric files? Then try the Font::AFM module.
best regards,
randy kobes
------------------------------
Date: 13 Jul 2000 02:46:15 GMT
From: michal@gortel.phys.ualberta.ca (Michal Jaegermann)
Subject: Re: New to perl, need help
Message-Id: <8kjahn$eas$1@pulp.srv.ualberta.ca>
Larry Rosler (lr@hpl.hp.com) wrote:
: In article <m11z0zqg0v.fsf@halfdome.holdit.com> on 12 Jul 2000 12:56:16
: -0700, Randal L. Schwartz <merlyn@stonehenge.com> says...
: ...
: > From the CPAN, get and install "Memoize". Then add to your program:
: >
: > use Memoize;
: > memoize('fibonacci');
: >
: > I bet it'll run tons faster after that. This is a classic function
: > that helps to be memoized.
: Indeed, but as so often, a module isn't needed to implement one line of
: code. All it is is the familiar Orkish Maneuver.
[ code skipped ... ]
What about something in the following style?
#!/usr/bin/perl
sub fibonacci {
my $number = shift;
my ($x, $y) = (0, 1);
while (1) {
return $x if $number-- < 1;
$x = $x + $y;
return $y if $number-- < 1;
$y = $x + $y;
}
}
print ((fibonacci shift), "\n");
This technique actually easily generalizes to any sequence
defined by a linear recursion.
Michal
------------------------------
Date: Thu, 13 Jul 2000 02:50:27 GMT
From: "Ecco" <ecco64@chello.nl>
Subject: Newbies cry for help
Message-Id: <T7ab5.363371$k22.1585697@flipper>
Greetings guru's! I just recently started programming with Perl, and I'm
looking for a script that pop-ups a new browser-window, but I have NO clue
how to do that... Thanx 4 ur time,
~ecco~
------------------------------
Date: 13 Jul 2000 01:17:55 +1000
From: "taboo" <taboo@doofa.net>
Subject: Re: Newbies cry for help
Message-Id: <396c8c23$1_3@nexus.comcen.com.au>
"Ecco" <ecco64@chello.nl> wrote:
>Greetings guru's! I just recently started programming with Perl, and I'm>looking for a script that pop-ups a new browser-window, but I have NO clue
>how to do that... Thanx 4 ur time,
> ~ecco~
>
>
try
<a href="somelink" target=_blank>some text</a>
ps this is not perl but HTML.
------------------------------
Date: Thu, 13 Jul 2000 03:37:18 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Newbies cry for help
Message-Id: <smqebeqgnd616@corp.supernews.com>
Ecco (ecco64@chello.nl) wrote:
: Greetings guru's!
Perl guru's what?
: I just recently started programming with Perl, and I'm
: looking for a script that pop-ups a new browser-window, but I have NO clue
: how to do that... Thanx 4 ur time,
That is a Javascript trick, not a Perl trick. You can write Perl that
outputs an HTML page containing Javascript that does this, but the same
can be said of any other web-capable language.
--
| Craig Berry - http://www.cinenet.net/users/cberry/home.html
--*-- "Beauty and strength, leaping laughter and delicious
| languor, force and fire, are of us." - Liber AL II:20
------------------------------
Date: Thu, 13 Jul 2000 03:43:10 GMT
From: "Ecco" <ecco64@chello.nl>
Subject: Re: Newbies cry for help
Message-Id: <iVab5.364389$k22.1585906@flipper>
Thanx, but the reason I want it in a Perl-script is; I need to create a
profile in a chat-box that pops-up the window. It only allows limited HTML
and NO JAVA, it does except Perl-scripts though.
--
-----------------------------------------------------
Click here for Free Video!!
http://www.gohip.com/free_video/
"taboo" <taboo@doofa.net> wrote in message
news:396c8c23$1_3@nexus.comcen.com.au...
>
> "Ecco" <ecco64@chello.nl> wrote:
> >Greetings guru's! I just recently started programming with Perl, and
I'm>looking for a script that pop-ups a new browser-window, but I have NO
clue
> >how to do that... Thanx 4 ur time,
> > ~ecco~
> >
> >
> try
> <a href="somelink" target=_blank>some text</a>
> ps this is not perl but HTML.
------------------------------
Date: Thu, 13 Jul 2000 11:47:30 +1000
From: David Rugendyke <nospam@one.net.au>
Subject: NNTP Newsgroup script problem!
Message-Id: <396D1FB2.1A5158FE@one.net.au>
Hi All,
Thanks for taking the time to read my small problem, any assistance in
this area is extremely appreciated, thanks.
I am writing a perl script which can log onto a newsgroup server, then
download the first ten articles and display their properties (subject
title, name, msg body etc.) in a html format. To do this I have been
using NNTPClient module... Here's the code so far....
sub readHeaders {
($first, $last) = ($c->group("alt.comp.hardware"));
$limit = $last - 10;
for (; $limit <= $last; $last--) {
$news = $c->article($last);
print "<br>--<br><TT>";
while ($news =~ m{subject(.*?)\date}isg){
$headerSubject = $1;
print "Headers: $headerSubject";
print "HIT!";
}
}
Now, that code logs onto alt.comp.hardware newsgroup, downloads 10
articles and as it does, it filters the subject title out and displays
it.
Problem... For some reason when you call an article directly using
$c->article($last) it delivers the entire article in text which is what
I want, only problem is when you pass that value to a variable like so
... $news = $c->article($last); it doesnt deliver the article, but the
Array address of the article.... eg.
print $c->article($last); = "Article Header info... text body
etc..."
$news = $c->article($last);
print $news; = "ARRAY(asd98x09800)"
I need the article in a scalar variable so I can extract the information
using...
while ($news =~ m{subject(.*?)\date}isg)
Anyway, if you made it this far without falling asleep and you may be
able to offer some help, then I am extremely gratefull and open to all
ideas...
Thanks,
Dave.
------------------------------
Date: Thu, 13 Jul 2000 10:19:15 +0800
From: Tom <chaptera@hotmail.com>
Subject: Perl new users:about locat the string in file?
Message-Id: <396D2723.D55873A3@hotmail.com>
My current situation is, I want to find a string from a file.
currently, I am using the script like this:
.....
open(file,"content.txt") or die "cannnot open";
while(<file>)
{
if ($_ =~ /patten/)
{
print "current line is " $. .......;
last;
}
}
close(file);
the file content like this:
AAAAAAA,BBBBBBBB,CCCCCCc
1111111111,DDDDDDDDDDDD,%%%%%%%%%%%
.........
Do you have any method faster than that?
I mean that easy to locate the position and find the string.
As of my file is greater than 3000 lines.
thanks!
------------------------------
Date: Thu, 13 Jul 2000 02:38:39 GMT
From: mcmorran@visi.net (Peter McMorran)
Subject: Re: Perl... the split function
Message-Id: <396d2baa$3$zpzbeena$mr2ice@news.visi.net>
In <8ki80u$58k$1@pegasus.csx.cam.ac.uk>, on 07/12/00
at 04:57 PM, mjtg@cus.cam.ac.uk (M.J.T. Guy) said:
>Antony <mcnultya@nortelnetworks.com> wrote:
>>
>>My problem is... how do you set the delimiters to be a 'space' and a
>>'comma' ?
>>
>>I have tried
>> split(/([, ])/, "1 10,20", 3);
>>But for some reason that doesn't work.
>What do you mean by "doesn't work"? What did you expect it to
>produce, and what did it actually produce?
>It does what I expect it to do (modulo some curiosity about the
>third argument):
> DB<1> x split(/([, ])/, "1 10,20", 3);
>0 1
>1 ' '
>2 10
>3 ','
>4 20
> DB<2>
Yes, it seems that the third argument is the number of the fields
that a normal split (without parens in the pattern) would return.
The parens cause the the delimiters to be returned as an added
bonus, but they are not included in the limiting count.
Interesting, but reasonable. So, if "doesn't work" means that it
returns a list of 5 items when I only asked for 3 fields, that's
true. It returns 3 data fields and the delimiters between them.
Incidentally, to make it treat repeated delimiters as a single
delimiter, use + in the pattern, as /([, ]+)/. Otherwise,
splitting "2, 3" produces a null field between the comma and the
space.
Cheers,
Peter
--
-----------------------------------------------------------
mcmorran@visi.net (Peter McMorran)
-----------------------------------------------------------
------------------------------
Date: Thu, 13 Jul 2000 13:52:55 +1200
From: "Peter Sundstrom" <peter.sundstrom@eds.com>
Subject: Re: PRINTing " "" "
Message-Id: <8kj7fa$bm7$1@hermes.nz.eds.com>
deno wrote in message <2ef35294.bc076b53@usw-ex0105-036.remarq.com>...
>
>Thats brillant
>
>Thanks
What's brilliant?
Remember that you should quote the appropriate text you are responding to.
Newservers propagate at different rates, so all I can see in this thread is
your question and your comments of "That's brilliant".
------------------------------
Date: 12 Jul 2000 20:05:33 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Problems with reading and printing file!
Message-Id: <87r98yhmaq.fsf@limey.hpcc.uh.edu>
>> On Thu, 13 Jul 2000 00:39:23 GMT,
>> "langtind" <arild@langtind.no> said:
> Can someone tell me way this code would not print to my
> HTML-page, but the last (print "HEI\n";) line does! The
> test.txt is a text-file with some lines with text. I
> want the script to read the file and print it into my
> web-page. If I make a print "something\n"; it gets into
> the web-page, but not the fil!
> open(FILE, "test.txt");
my $filename = 'test.txt';
open FILE, $filename or die "Can't open file $filename: $!\n";
Always check open()'s status.
use CGI::Carp 'fatalsToBrowser';
will help here.
I suspect:
Your CGI program is not executing in the directory you
think it is.
http://www.boutell.com/openfaq/cgi/
hth
t
--
"With $10,000, we'd be millionaires!"
Homer Simpson
------------------------------
Date: Thu, 13 Jul 2000 01:24:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Problems with reading and printing file!
Message-Id: <396D1AA7.250104CD@rochester.rr.com>
langtind wrote:
>
> Can someone tell me way this code would not print to my HTML-page, but the
> last (print "HEI\n";) line does!
> The test.txt is a text-file with some lines with text.
> I want the script to read the file and print it into my web-page.
> If I make a print "something\n"; it gets into the web-page, but not the fil!
>
> open(FILE, "test.txt");
> while ($line = <FILE>)
> {
> print "$line";
> }
> close(FILE);
> print "HEI\n";
>
> Trond Aage
It's probably because your open failed for some reason. *Always*
*always* check for success of your open with code like:
open FILE,"test.txt" or die "Couldn't open test.txt, $!\n";
--
Bob Walton
------------------------------
Date: Wed, 12 Jul 2000 21:48:39 -0500
From: "Rodney Rindels" <rrindels@arkansas.net>
Subject: Re: regex question
Message-Id: <Obab5.1134$PI1.79804@news-west.usenetserver.com>
I am indeed a moth on a journey..I will either eats someones shirt off their
back or get burned.
Thank You,
Rodney
Abigail <abigail@delanet.com> wrote in message
news:slrn8mq4a1.dun.abigail@alexandra.delanet.com...
> Rodney Rindels (rrindels@arkansas.net) wrote on MMDVII September MCMXCIII
> in <URL:news:mG3b5.4$PI1.1342@news-west.usenetserver.com>:
> @@ I am using Mason and mod_perl on apache. The question I have is in
regards
> @@ to matching a password string , strict is in use by default under
Mason.
> @@
> @@ if ($pass1=~/[!@#$%^&*()]/){
> @@ #cannot continue to register
> @@ } else {
> @@ #ok register
> @@ }
> @@
> @@ I thought this would not allow the character in the [] to be in the
string
> @@ ,
> @@ but this also fails if a 0 is in the string all other numeric values
work
> @@ correctly. It does not matter where the 0 is in the string whether
> @@ $pass1="foo0" or $pass1="10" or $pass1="0bar"
>
> perl -wle 'print $%' will enlight you.
>
>
>
> Abigail
> --
> perl -MNet::Dict -we '(Net::Dict -> new (server => "dict.org")
> -> define ("foldoc", "perl")) [0] -> print'
------------------------------
Date: 12 Jul 2000 20:09:44 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: using %ENV with CGI
Message-Id: <87og42hm3r.fsf@limey.hpcc.uh.edu>
>> On Thu, 13 Jul 2000 12:53:33 +1200,
>> "Trent Mankelow" <trent.mankelow@unisys.com> said:
> use lib "$ENV{NIKAUHOME}/lib";
> to add the lib directory to @INC, it comes back and
> tells me that it can't find the environment variable
> $NIKAUHOME. I've got a setup script that sets this
> variable by "sourcing" a file that has the following
> line in it:
> setenv NIKAUHOME /home/peri/nikau
How do you source this? CGI programs run as children of
the web server. Therefore the web server has to know
about the environment setting.
I think this might be better addressed in a cgi or
web-server specific newsgroup.
hth
t
--
"With $10,000, we'd be millionaires!"
Homer Simpson
------------------------------
Date: Thu, 13 Jul 2000 14:08:57 +1200
From: "Trent Mankelow" <trent.mankelow@unisys.com>
Subject: Re: using %ENV with CGI
Message-Id: <8kj8al$ovj$1@mail.pl.unisys.com>
I'm sourcing it by simply typing "source setup.csh" at the moment, and then
restarting the server afterwards, by typing "/etc/init.d/httpd stop"
followed by "/etc/init.d/httpd start".
Sorry, you might be right. Although this is a question relating to Perl, I
guess it doesn't really belong in this NG.
"Tony Curtis" <tony_curtis32@yahoo.com> wrote in message
news:87og42hm3r.fsf@limey.hpcc.uh.edu...
> >> On Thu, 13 Jul 2000 12:53:33 +1200,
> >> "Trent Mankelow" <trent.mankelow@unisys.com> said:
>
> > use lib "$ENV{NIKAUHOME}/lib";
>
> > to add the lib directory to @INC, it comes back and
> > tells me that it can't find the environment variable
> > $NIKAUHOME. I've got a setup script that sets this
> > variable by "sourcing" a file that has the following
> > line in it:
> > setenv NIKAUHOME /home/peri/nikau
> How do you source this? CGI programs run as children of
> the web server. Therefore the web server has to know
> about the environment setting.
>
> I think this might be better addressed in a cgi or
> web-server specific newsgroup.
>
> hth
> t
> --
> "With $10,000, we'd be millionaires!"
> Homer Simpson
------------------------------
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 3646
**************************************