[25273] in Perl-Users-Digest
Perl-Users Digest, Issue: 7518 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Dec 14 14:11:28 2004
Date: Tue, 14 Dec 2004 11:05:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 14 Dec 2004 Volume: 10 Number: 7518
Today's topics:
[Slightly OT] Perl interpreter (win32) single "threaded <not@home.net>
Re: Consecutive Numbers <perl@my-header.org>
Re: Consecutive Numbers <perl@my-header.org>
Re: Down and dirty Britney Spears [virus] <x3v0-usenet@yahoo.com>
Re: FAQ 4.36: How can I expand variables in text string <nobull@mail.com>
go to a link, save the page and email it out? <zhangd@tycoelectronics.com>
Re: go to a link, save the page and email it out? <perl@my-header.org>
Re: go to a link, save the page and email it out? <apeiron+usenet@coitusmentis.info>
Re: go to a link, save the page and email it out? <apeiron+usenet@coitusmentis.info>
Re: hashes <matternc@comcast.net>
Re: How to do this job? <eon@hotmail.com>
Re: how to read email automatically without POP3 and IM <bmetcalf@nortelnetworks.com>
Re: mkdir <nospam@spambucket.foo>
Re: Newbie questions, migrating from c++ <matthew.garrish@sympatico.ca>
opening a temp window from a perl script? <dlr93612@yahoo.com>
Re: opening a temp window from a perl script? <spamtrap@dot-app.org>
pause, wait, etc. <nospam@nospam.com>
Re: pause, wait, etc. <mritty@gmail.com>
Re: pause, wait, etc. <spamtrap@dot-app.org>
Re: pause, wait, etc. <nospam@nospam.com>
Quick easy question... <big.e12@gmail.com>
Re: Quick easy question... (Anno Siegel)
Re: Quick easy question... <spamtrap@dot-app.org>
Re: Quick easy question... <richard@zync.co.uk>
Re: Quick easy question... (Anno Siegel)
Re: Quick easy question... <richard@zync.co.uk>
Re: Quick easy question... <a.newmane.remove@eastcoastcz.com>
Read mail file? (Linux) <xxxx@yyyy.zzzz>
Re: Read mail file? (Linux) <apeiron+usenet@coitusmentis.info>
Re: Read mail file? (Linux) <spamtrap@dot-app.org>
Re: Read mail file? (Linux) (David Efflandt)
Relational databases and tied hashes? (Lee Goddard)
Re: Relational databases and tied hashes? <spamtrap@dot-app.org>
Re: Relational databases and tied hashes? <perl@my-header.org>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 14 Dec 2004 18:11:05 GMT
From: "JayEs" <not@home.net>
Subject: [Slightly OT] Perl interpreter (win32) single "threaded"?
Message-Id: <Z0Gvd.39811$bP2.22992@newssvr12.news.prodigy.com>
First off I am sure that a lot of you folks will have the inclination to
answer my Q with : Oh, that's a windoze thing. Matter of fact, that's what I
thought at first myself, but... Not anymore. With that out of the way, Here
is my Q:
Is ActiveState Perl not able to run twice?? I was writing a few scripts
using the Mech and IE::Mech And when I started several copies I noticed that
the different copies of the scripts were "waiting for each othet", in other
words: One copy would pause until the Second copy executed a block of code
before continuing itself and thus pausing copy One.
I realized that all scripts (hey, just testing stuff) were all writing
output to the same file. I figured they must be waiting for access to the
file on disk. I took that part out of all the scripts, same thing! Copy One
waits for copy Two.
Since the entire point of the excercise is to see how well Perl behaves if
started (multiple copies of scripts simultaneously) from an outside source
(be it .BAT, shell function in other language, etc...) I then checked to see
if Perl itself would be any better at it. So I wrote a quickie script that
utilizes Win32::Process::Create and used it to start Perl scriptname.pl
Same thing occurs, One waits for Two....
So I downloaded a trial copy of Perl2Exe, thinking that if I compile all the
scripts to exe's and start several copies of them, they must all clearly be
running in their own thread space....
WRONGO! Same problem!
Perl is not a service on Win32. It gets called when it is asked for. If you
start a script in say, OpenPerl and drop a breakpoint in the middle, then go
to the Win taskman, you will find Perl.exe, which goes away as soon as the
script ends...
Is Perl.exe or one of its dlls only single threaded? Do all copies of all
scripts run through one interpreter?? What is the deal here?? If I start two
scripts (started from 2 different command lines) I clearly get 2 copies of
perl.exe in the taskman. Why then are these scripts still appearing to wait
for each other??
------------------------------
Date: Tue, 14 Dec 2004 18:51:06 +0100
From: Matija Papec <perl@my-header.org>
Subject: Re: Consecutive Numbers
Message-Id: <2i9ur0559qcu9qm5q72p8hbfqk0hcj1g5o@4ax.com>
X-Ftn-To: Anno Siegel
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
> sub is_arithmetic_sequence {
> my $delta = shift;
> while ( @_ > 1 ) {
> $_ + $delta == $_[ 0] or return 0 for shift;
> }
> return 1;
> }
=== my benchmark ===
> Rate foreach plain nosub_foreach nosub_plain
>foreach 5698/s -- -68% -91% -92%
>plain 17913/s 214% -- -72% -75%
>nosub_foreach 64412/s 1030% 260% -- -11%
>nosub_plain 72595/s 1174% 305% 13% --
I know that foreach is costly, even when using it only to topicalize
scalars. What baffles me here, is that there is far greater difference
between first two benchmarks => (foreach:plain = 1:3.14; your
is_arithmetic_sequence runs three times faster without foreach) compared to
next two 1:1.12 ?:)
Is Benchmark being misused?
use Benchmark qw(:all);
use strict;
sub is_arithmetic_sequence {
my $delta = shift;
while ( @_ > 1 ) {
$_ + $delta == $_[ 0] or return 0 for shift;
}
return 1;
}
sub is_arithmetic_sequence2 {
my $delta = shift;
while ( @_ > 1 ) {
(shift) + $delta == $_[ 0] or return 0;
}
return 1;
}
cmpthese(40_000, {
foreach => sub {
my @r = 0..30;
is_arithmetic_sequence(1, @r);
},
plain => sub {
my @r = 0..30;
is_arithmetic_sequence2(1, @r);
},
nosub_foreach => sub {
my @r = 0..30;
my $delta = 1;
while ( @r > 1 ) {
$_ + $delta == $_[ 0] or return 0 for shift @r;
}
return 1;
},
nosub_plain => sub {
my @r = 0..30;
my $delta = 1;
while ( @r > 1 ) {
(shift @r) + $delta == $_[ 0] or return 0;
}
return 1;
}
});
--
Matija
------------------------------
Date: Tue, 14 Dec 2004 19:42:58 +0100
From: Matija Papec <perl@my-header.org>
Subject: Re: Consecutive Numbers
Message-Id: <okcur050b2bcmg8kqistuc8m3n1qje779t@4ax.com>
X-Ftn-To: Matija Papec
Matija Papec <perl@my-header.org> wrote:
>is_arithmetic_sequence runs three times faster without foreach) compared to
>next two 1:1.12 ?:)
>Is Benchmark being misused?
I was using wrong arrays in last two subs. ;)
> Rate nosub_foreach foreach nosub_plain plain
>foreach 5698/s 5% -- -64% -68%
>plain 17841/s 228% 213% 12% --
>nosub_foreach 5434/s -- -5% -66% -70%
>nosub_plain 15981/s 194% 180% -- -10%
It seems that foreach is main speed killer.
--
Matija
------------------------------
Date: Tue, 14 Dec 2004 12:50:52 -0500
From: Ken <x3v0-usenet@yahoo.com>
Subject: Re: Down and dirty Britney Spears [virus]
Message-Id: <0KFvd.164$tV6.154@fe37.usenetserver.com>
megan wrote:
> Britney Spears
>
>
>
>
Virus alert. Why somebody posted it here, I don't know.
------------------------------
Date: Tue, 14 Dec 2004 18:22:50 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: FAQ 4.36: How can I expand variables in text strings?
Message-Id: <cpnaof$6c0$1@sun3.bham.ac.uk>
brian d foy wrote:
> In article <etod5xd1yxv.fsf@wilson.emschwar>, Eric Schwartz
> <emschwar@pobox.com> wrote:
>
>
>>Brian McCauley <nobull@mail.com> writes:
>>
>>>PerlFAQ Server wrote:
>
>
>>>>4.36: How can I expand variables in text strings?
>
>
>>>This is question is clearly asking for a simple templating system.
>
>
>>Perhaps restating the question as something along the lines of one of
>>these might help:
>
>
>>* How can I expand a variable name in text strings?
>>* How can I replace a string with the contents of a variable?
As I described in my lighting-talk at YAPC::Europe::2004, about half the
time this question is actually posed as a question about s/// and the
variables the asker is interested in interpolating are $1 et al. The
asker does not realise that their question about s/// actually
generalises to a question about strings.
So long as the question as it appears in the FAQ does not mention s///
half the people with this question have essentially no chance of
realising the are, in fact, asking a FAQ.
> That's what I thought too: the input string is beyond our
> control and we just get to deal with it.
I've made quite a study of this question over the years and in pratice
it is rare that the input is beyond the asker's control.
It is very rare (indeed I doubt I've _ever_ seen a case[1]) that the
input is beyond the asker's control _and_ that the answer in the FAQ
would be satifactory. When the input syntax is beyond the asker's
control then it is probably defined as "Perl like" and so the current
answer is inadequate because it doesn't correctly handle:
$text = 'this has a $foo in it, a literal \$foo and also ${bar}s';
Sure it is possible to refine the soultion until it does but people
should be presented with sufficient information to make an informed
choice whether or not to use the simple chop-eval-here-doc solution.
At the the moment they either make an uninformed choice not to use eval
(because they are not told of it) or and uninformed choice to use eval
(because they are not warned of the hazards).
[1] URLs to disproove this wellcome.
------------------------------
Date: 14 Dec 2004 09:49:16 -0800
From: "dale" <zhangd@tycoelectronics.com>
Subject: go to a link, save the page and email it out?
Message-Id: <1103046556.435866.299500@f14g2000cwb.googlegroups.com>
Hi,
Does anyone know if there is a perl module to do the above?
Thanks. -Dale
------------------------------
Date: Tue, 14 Dec 2004 18:58:41 +0100
From: Matija Papec <perl@my-header.org>
Subject: Re: go to a link, save the page and email it out?
Message-Id: <lcaur0h5i13vndt0pkt1718gpt7ffehnrk@4ax.com>
X-Ftn-To: dale
"dale" <zhangd@tycoelectronics.com> wrote:
>Does anyone know if there is a perl module to do the above?
HTML::Mail works nicely.
--
Matija
------------------------------
Date: 14 Dec 2004 18:20:04 GMT
From: Christopher Nehren <apeiron+usenet@coitusmentis.info>
Subject: Re: go to a link, save the page and email it out?
Message-Id: <slrncrubmk.opg.apeiron+usenet@prophecy.dyndns.org>
On 2004-12-14, dale scribbled these
curious markings:
> Does anyone know if there is a perl module to do the above?
> Thanks. -Dale
package MailPage;
use strict;
use warnings FATAL => 'all';
use LWP::Simple;
use MIME::Lite;
use Carp;
use base qw/Exporter/;
use vars qw/@EXPORT_OK/;
@EXPORT_OK = qw/mail_page/;
sub mail_page
{
croak "mail_page needs four arguments!" unless @_ == 4;
my ($page, $from, $to, $subject) = @_;
my $content = get($page);
croak "Couldn't fetch $page!" unless defined $content;
my $msg = MIME::Lite->new
(
From => $from,
To => $to,
Subject => $subject,
Data => $content,
);
$msg->send() or carp "Uh oh, problems sending mail!"
}
1;
__END__
#!/usr/bin/perl
use strict;
use warnings FATAL => 'all';
use MailPage qw/mail_page/;
mail_page(q#http://www.google.com#, q#apeiron@coitusmentis.info#,
q#apeiron@coitusmentis.info#, q#A Test#);
__END__
WFM. Took about 5 minutes (mostly because I'm not too familiar with most
of the modules used).
/me braces for the inevitable torrent of code review he's going to
receive...
Best Regards,
Christopher Nehren
--
I abhor a system designed for the "user", if that word is a coded
pejorative meaning "stupid and unsophisticated". -- Ken Thompson
If you ask the wrong questions, you get answers like "42" and "God".
Unix is user friendly. However, it isn't idiot friendly.
------------------------------
Date: 14 Dec 2004 18:21:50 GMT
From: Christopher Nehren <apeiron+usenet@coitusmentis.info>
Subject: Re: go to a link, save the page and email it out?
Message-Id: <slrncrubpu.opg.apeiron+usenet@prophecy.dyndns.org>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
On 2004-12-14, Christopher Nehren scribbled these
curious markings:
> $msg->send() or carp "Uh oh, problems sending mail!"
^^^^
Self-review: that should probably be croak.
Best Regards,
Christopher Nehren
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.6 (FreeBSD)
iD8DBQFBvy8+k/lo7zvzJioRAq4RAKCZDdQsKGN3Qwt526VnfKUfaXss+QCgluo4
Uzpdd3l6dWZ7lutd+tTY288=
=JDeH
-----END PGP SIGNATURE-----
--
I abhor a system designed for the "user", if that word is a coded
pejorative meaning "stupid and unsophisticated". -- Ken Thompson
If you ask the wrong questions, you get answers like "42" and "God".
Unix is user friendly. However, it isn't idiot friendly.
------------------------------
Date: Tue, 14 Dec 2004 06:13:05 -0500
From: Chris Mattern <matternc@comcast.net>
Subject: Re: hashes
Message-Id: <j_adnS0EZ45cVyPcRVn-oQ@comcast.com>
anon1ed2@nyx.net wrote:
> Sherm -- good to hear from you buddy!
>
> The code, per your request, is as so:
>
> #!/usr/bin/perl -w
# use warnings; is better than -w
use strict;
> my %wordsTbl = (
> john => "camel",
> paul => "llama",
> ringo => "alpaca",
> george => "horse",
> );
>
> print "What is your name? ";
> $name = <STDIN>;
> chomp ($name);
> if ($name eq "caius") {
> print "Hello $name, it's wonderful you're here!\n";
> } else {
> print "What's your story $name?\n"; #cautious greeting
> $secretword = $wordsTbl($name); #DIES HERE!
Well, yeah. You specify the index of a hash with {}, not ().
> print "Hock! $secretword\n";
> print "What's the secret word? ";
> $guess = <STDIN>;
> chomp ($guess);
> while ($guess ne $secretword) { # keep checking til we know
> print "Wrong, try again. What is the secret word? ";
> $guess = <STDIN>;
> chomp ($guess);
> } # end while
> } # end else
>
> Error message, per your request, is as so:
>
> Syntax error at tst6.pl line 16, near "$wordsTbl("
> Execution aborted due to compilation errors.
>
> Tried playing with all kinds of variations to no avail.
> I didn't initially include the code because, as far as
> I can tell, there is no syntax error,
No, you can't tell, and yes, there is a syntax error.
> and I wondered if
> this was just a standard error about which perl
> people know.
>
> caius
--
Christopher Mattern
"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
------------------------------
Date: Tue, 14 Dec 2004 14:07:12 GMT
From: "Leon" <eon@hotmail.com>
Subject: Re: How to do this job?
Message-Id: <ksCvd.497$c46.270@newsfe4-gui.ntli.net>
"news.hinet.net" <sonet.all@msa.hinet.net> wrote in message
news:cpm0cu$8kh$1@netnews.hinet.net...
> Direcory:
> /usr/local/ap/
> Filename:
> 1
> 1.lock
> 2
> 3
> 4
> 4.lock
>
> want to list 2 and 3.
> ========================================================
> opendir(DIR,"/usr/local/ap/");
> @dots = grep {-f "/usr/local/ap/$_" && $_ !~m/\.lock/} readdir(DIR);
> close(DIR);
> ========================================================
> The @dots have 1 2 3 4 elements. I know i can use -e to check the
> $filename.lock in loop.
> But how to make @dots just have 2 and 3? Becaues the directory have
> many files,i don't want to worse time to check the $filename.lock .
> please help!
>
> thanks!
>
#!/usr/bin/perl
use strict;
use warnings;
opendir(DIR, "/usr/local/ap/");
# Grep statement additionally checks that the current file doesn't end with
.lock AND that there isn't
# a .lock file. For instance, if current file was 1.lock then ! -e
"/usr/local/ap/$_.lock" would have been
# checking for the existance of 1..lock.lock. Could get slightly confusing
results.
my @dots = grep{-f "/usr/local/ap/$_" && $_ !~ m/\.lock$/ && ! -e
"/usr/local/ap/$_.lock"}readdir(DIR);
closedir(DIR);
# This worked on my system:)
------------------------------
Date: Tue, 14 Dec 2004 18:17:02 +0000 (UTC)
From: Brandon Metcalf <bmetcalf@nortelnetworks.com>
Subject: Re: how to read email automatically without POP3 and IMAP servers in perl?
Message-Id: <slrncrub8f.f9r.bmetcalf@cash.rhiamet.com>
On 2004-12-13, dale <zhangd@tycoelectronics.com> wrote:
> I have verizon dsl service at home. I guess that they have pop3 server
> for receiving mails. I tried to telnet or ping to incoming.verizon.net.
> None of them works.
>
> Any idea? -Dale
Although this is way off topic, I can ping this host and telnet to port
110 which is where the POP3 server is listening:
$ ping -c 2 incoming.verizon.net
PING mail.verizon.net (206.46.170.10): 56 data bytes
64 bytes from 206.46.170.10: icmp_seq=0 ttl=235 time=28.8 ms
64 bytes from 206.46.170.10: icmp_seq=1 ttl=235 time=24.7 ms
--- mail.verizon.net ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 24.7/26.7/28.8 ms
$ telnet incoming.verizon.net 110
Trying 206.46.170.10...
Connected to mta1pub.gte.net.
Escape character is '^]'.
+OK InterMail POP3 server ready.
--
Brandon
------------------------------
Date: Tue, 14 Dec 2004 17:28:33 +0000 (UTC)
From: Bugblatter <nospam@spambucket.foo>
Subject: Re: mkdir
Message-Id: <cpn7s1$2b9$1@hercules.btinternet.com>
Freak wrote:
> Hi all
> can somene post sample of creating directory, ie:
> I have
> www.domain.com
> Now I need this:
> www.domain.com/directory1
>
> Thank you
>
>
chdir $documentroot or die "Where the heck is my website stored?";
mkdir directory1 or die "unable to make directory: $!";
------------------------------
Date: Tue, 14 Dec 2004 09:41:32 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Newbie questions, migrating from c++
Message-Id: <sYCvd.7600$pb.512670@news20.bellglobal.com>
"Dave Weaver" <zen13097@zen.co.uk> wrote in message
news:41beafbd$0$1076$db0fefd9@news.zen.co.uk...
> On Sun, 12 Dec 2004 13:47:50 -0500,
> Matt Garrish <matthew.garrish@sympatico.ca> wrote:
>>
>> s/^(\s+)/print length($1)/e;
>
>
> Yuk! That seems quite convoluted, and also needlessly destroys your
> source string:
>
I read too much into his post, it seems. I was under the impression that he
wanted to remove and count the whitespace. And granted, in looking back that
is one ugly regex. Must have been having one big brain fart when I wrote
that... : )
Matt
------------------------------
Date: 14 Dec 2004 10:32:03 -0800
From: "Lisa" <dlr93612@yahoo.com>
Subject: opening a temp window from a perl script?
Message-Id: <1103049123.884145.151700@f14g2000cwb.googlegroups.com>
How can I do the following?
I have a script thru which a user from the web can up load an image
file. I would like, when the user clicks the "Send Image" button, to
pop up a small window containing an animated working (please be
patient) .gif while the image is uploaded from thier computer to the
server, once the transfer is complete, I would like to close the pop up
window and then load the new page in the original window.
Or at least somthing closely resembling this sequence of events to let
users on "dialup's" the something is going on and to be patient.
Lisa
------------------------------
Date: Tue, 14 Dec 2004 13:43:30 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: opening a temp window from a perl script?
Message-Id: <DrWdnRX8uPnOqSLcRVn-gg@adelphia.com>
Lisa wrote:
> I have a script thru which a user from the web can up load an image
> file. I would like, when the user clicks the "Send Image" button, to
> pop up a small window containing an animated working (please be
> patient) .gif while the image is uploaded from thier computer to the
> server, once the transfer is complete, I would like to close the pop up
> window and then load the new page in the original window.
Based on your description, I'm assuming that when you say "I have a
script", you're talking about a Perl script that's called as a CGI to
handle the form submission from the browser.
That being the case, your Perl script won't be called at all until the
upload is finished, at which point its too late to do something like
what you're describing here.
There might be some JavaScript or other client-side haquery you could
use, but that's a question for another group.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: Tue, 14 Dec 2004 11:24:54 -0500
From: "daniel kaplan" <nospam@nospam.com>
Subject: pause, wait, etc.
Message-Id: <1103041464.304626@nntp.acecape.com>
Hi all,
Am looking for some type of a "pause" function. Long story short, have
written a quick script that will send out, one time only, some 400 emails
(reminders for a specific event).
My thing is this, while I am using:
unless(open (MAIL, "| /usr/sbin/sendmail -t -oi -odq"))
with the "queue" parameter, truth is, I don't really trust the mail server
at my hosting place. I would swear, they sneeze and the mail server goes
down. So putting 400 emails in their queue, I just don't trust. At the
same time, turning off the "queue" is rude, and would be far worse than
sneezing!
So I looked for some type of function that would pause my script for X
seconds, in between each email. But between CPAN and perldoc came up short.
Does such a beast exist?
Thanks ahead, as always!
Daniel
------------------------------
Date: Tue, 14 Dec 2004 16:29:20 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: pause, wait, etc.
Message-Id: <AxEvd.9511$sU4.5086@trndny01>
"daniel kaplan" <nospam@nospam.com> wrote in message
news:1103041464.304626@nntp.acecape.com...
> Am looking for some type of a "pause" function.
perldoc -f sleep
Paul Lalli
------------------------------
Date: Tue, 14 Dec 2004 11:33:30 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: pause, wait, etc.
Message-Id: <i96dne_dnedGiCLcRVn-ug@adelphia.com>
daniel kaplan wrote:
> So I looked for some type of function that would pause my script for X
> seconds
perldoc -f sleep
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: Tue, 14 Dec 2004 13:16:58 -0500
From: "daniel kaplan" <nospam@nospam.com>
Subject: Re: pause, wait, etc.
Message-Id: <1103048187.12114@nntp.acecape.com>
"Paul Lalli" <mritty@gmail.com> wrote in message
news:AxEvd.9511$sU4.5086@trndny01...
> perldoc -f sleep
DOH! thanks
------------------------------
Date: 14 Dec 2004 07:57:55 -0800
From: "big.e12" <big.e12@gmail.com>
Subject: Quick easy question...
Message-Id: <1103039875.310902.203610@c13g2000cwb.googlegroups.com>
I am just getting started in perl and I was wondering if someone could
help me out... I am trying to write a script that counts the number of
times a word appears in the input. Can anyone help me?
------------------------------
Date: 14 Dec 2004 16:21:35 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Quick easy question...
Message-Id: <cpn3uf$beu$1@mamenchi.zrz.TU-Berlin.DE>
big.e12 <big.e12@gmail.com> wrote in comp.lang.perl.misc:
Telling your readers, first thing, that you think the question is
"quick and easy" is not very clever. I, for one, don't like to
be told what the question is like by someone who obviously doesn't
have the slightest idea how to solve it.
> I am just getting started in perl and I was wondering if someone could
> help me out... I am trying to write a script that counts the number of
> times a word appears in the input. Can anyone help me?
Homework? What have you tried so far, and in which way does it fail
to solve the problem?
Anno
------------------------------
Date: Tue, 14 Dec 2004 11:28:13 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Quick easy question...
Message-Id: <xtmdndk3KOwAiSLcRVn-tA@adelphia.com>
big.e12 wrote:
> I am just getting started in perl and I was wondering if someone could
> help me out... I am trying to write a script that counts the number of
> times a word appears in the input. Can anyone help me?
What have you tried so far? What were the results, and how were they
different from what you expected them to be?
Have you read the posting guidelines for this group? They're posted here
twice a week.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: Tue, 14 Dec 2004 16:39:51 +0000
From: Richard Gration <richard@zync.co.uk>
Subject: Re: Quick easy question...
Message-Id: <pan.2004.12.14.16.39.51.894619@zync.co.uk>
On Tue, 14 Dec 2004 07:57:55 -0800, big.e12 wrote:
> I am just getting started in perl and I was wondering if someone could
> help me out... I am trying to write a script that counts the number of
> times a word appears in the input. Can anyone help me?
How about this?
perl -e 'print [map{$t+=$_=~s/homework//g}<STDIN>]->[-1]'
------------------------------
Date: 14 Dec 2004 17:10:34 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Quick easy question...
Message-Id: <cpn6qa$e3o$1@mamenchi.zrz.TU-Berlin.DE>
Richard Gration <richard@zync.co.uk> wrote in comp.lang.perl.misc:
> On Tue, 14 Dec 2004 07:57:55 -0800, big.e12 wrote:
>
> > I am just getting started in perl and I was wondering if someone could
> > help me out... I am trying to write a script that counts the number of
> > times a word appears in the input. Can anyone help me?
>
> How about this?
>
> perl -e 'print [map{$t+=$_=~s/homework//g}<STDIN>]->[-1]'
Hey, that's a joke, right? You can't be serious...
Anno
------------------------------
Date: Tue, 14 Dec 2004 17:20:08 +0000
From: Richard Gration <richard@zync.co.uk>
Subject: Re: Quick easy question...
Message-Id: <pan.2004.12.14.17.20.08.172319@zync.co.uk>
On Tue, 14 Dec 2004 17:10:34 +0000, Anno Siegel wrote:
> Richard Gration <richard@zync.co.uk> wrote in comp.lang.perl.misc:
>> On Tue, 14 Dec 2004 07:57:55 -0800, big.e12 wrote:
>>
>> > I am just getting started in perl and I was wondering if someone
>> > could help me out... I am trying to write a script that counts the
>> > number of times a word appears in the input. Can anyone help me?
>>
>> How about this?
>>
>> perl -e 'print [map{$t+=$_=~s/homework//g}<STDIN>]->[-1]'
>
> Hey, that's a joke, right? You can't be serious...
>
> Anno
Well, it's a joke in the sense that I thought I smelled homework therefore
tried to obfuscate the answer :-)
But it's not a joke in the sense that it does work ... at least I think it
does ... I tested it on a some inputs and it seemed OK ... is it faulty?
Rich
------------------------------
Date: Tue, 14 Dec 2004 10:16:48 -0800
From: "Alfred Z. Newmane" <a.newmane.remove@eastcoastcz.com>
Subject: Re: Quick easy question...
Message-Id: <328p0iF3hnftcU1@individual.net>
"Richard Gration" <richard@zync.co.uk> wrote in message
> >> How about this?
> >>
> >> perl -e 'print [map{$t+=$_=~s/homework//g}<STDIN>]->[-1]'
> >
> > Hey, that's a joke, right? You can't be serious...
> >
> > Anno
>
> Well, it's a joke in the sense that I thought I smelled homework
therefore
> tried to obfuscate the answer :-)
I may have just been someone who is just starting out. I've yet to se
Perl taught in college courses (I haven't seen any available in any
colleges around here nor where I've attended.)
Even if it was home work, sometimes it can help a learner from working
by examples. When I was first learning Perl a few years ago, I was
constantly trying new things, see what would work, looking up examples
online and in docs, and in deja/google-groups.
True he could of found the answer by looking elsewhere (I think this one
might be in the FAQ), though I think pushing someone like this in the
right direction, who may not have /yet/ gotten a feel of how things work
around here. That is, tell them where the many good places are to look
(google, FAQ, perldoc, etc), instead of confusing them even more :-)
------------------------------
Date: Tue, 14 Dec 2004 10:04:17 -0800
From: "Crom" <xxxx@yyyy.zzzz>
Subject: Read mail file? (Linux)
Message-Id: <cpn9u2$u6m$1@news.astound.net>
How can I parse my mail spool file? Like in /var/spool/mail (and I think
the mailbox file in my home dir follows the same format.)
I've been trying to find this on google groups, but could not find
anything that really answers this.
Thanks for any help.
-----
(And by the way, what the hell did they do to google groups? It looks
nice and all but when reading a threaded view it's very hard to see
where one post ends and another begins, unless you click "show options".
am I the only one who thinks google groups was fine the way it was
before?????)
------------------------------
Date: 14 Dec 2004 18:29:55 GMT
From: Christopher Nehren <apeiron+usenet@coitusmentis.info>
Subject: Re: Read mail file? (Linux)
Message-Id: <slrncruc93.opg.apeiron+usenet@prophecy.dyndns.org>
On 2004-12-14, Crom scribbled these
curious markings:
> How can I parse my mail spool file? Like in /var/spool/mail (and I think
> the mailbox file in my home dir follows the same format.)
I personally like the Mail::Box suite. Whenever I've needed to do
something with email, it's come through for me (except for that one time
when I was fiddling with STDOUT, STDIN, and STDERR, but I'm sure that
its not working was my fault somewhere along the line...). I'm not one
for the simplicity of the Email:: namespace -- but then, I despise
simplicity in general. If you want simplicity, then I recommend
Email::Folder; a cursory glance yields it to do what you want.
However, if you want more complete functionality and a unified API, then
I wholeheartedly recommend Mail::Box.
> am I the only one who thinks google groups was fine the way it was
> before?????)
There's a still-growing thread about this in news.software.readers.
You're not alone. I personally don't care, since I use a Real
Newsreader.
Best Regards,
Christopher Nehren
--
I abhor a system designed for the "user", if that word is a coded
pejorative meaning "stupid and unsophisticated". -- Ken Thompson
If you ask the wrong questions, you get answers like "42" and "God".
Unix is user friendly. However, it isn't idiot friendly.
------------------------------
Date: Tue, 14 Dec 2004 13:32:42 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Read mail file? (Linux)
Message-Id: <8YadnVfwms1WrCLcRVn-tw@adelphia.com>
Crom wrote:
> How can I parse my mail spool file? Like in /var/spool/mail (and I think
> the mailbox file in my home dir follows the same format.)
Dunno if it's the same format as the mail spool or not, but there are a
couple of modules on CPAN for working with the standard mbox format:
Mail::Mbox::MessageParser
Mail::MboxParser
> I've been trying to find this on google groups
Nothing wrong with searching Google groups, but it's not a substitute
for searching CPAN. You really should search both.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: Tue, 14 Dec 2004 19:02:04 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Read mail file? (Linux)
Message-Id: <slrncrue5c.lh.efflandt@typhoon.xnet.com>
On Tue, 14 Dec 2004 10:04:17 -0800, Crom <xxxx@yyyy.zzzz> wrote:
> How can I parse my mail spool file? Like in /var/spool/mail (and I think
> the mailbox file in my home dir follows the same format.)
In the main spool file any line that begins with "From " (From followed by
a space, which as a regex would be /^From / ) marks the start of the next
message. Not sure if From is always capitalized. This is not to be
confused with "From:" (w/colon) which is within headers, if present.
Search for 'mail parse' on www.perl.com for examples of perl handling of
mail including an overview http://www.perl.com/pub/a/2004/06/10/email.html
------------------------------
Date: 14 Dec 2004 07:26:16 -0800
From: leegee@gmail.com (Lee Goddard)
Subject: Relational databases and tied hashes?
Message-Id: <30da21ec.0412140726.d1cbc4a@posting.google.com>
Is there a perl module to make life easier with relational,
linked databases?
For example, three tables, where each has a column acting as
a unique identifier (*.uid). The "item" table references the
"stock" table in the item.stock column using the stock.uid column;
the "item" table references the "image" table in the item.image
column using the item.uid column.
ITEM TABLE STOCK TABLE IMAGE TABLE
item.uid stock.uid image.uid
item.name stock.quantity image.href
item.price stock.others image.others
item.stock
item.image
I'd like a hash for every record I pull out of the "item" table,
and one that doesn't just give me the "item.stock" uid that is
there, but does the look-up and give me a hash of the relevant record:
$item->{
uid => 12,
name => "My Name",
price => '',
stock => {
uid => 103,
quantity=> 1,
others => 'other stuff',
},
image => {
uid => 43,
href => 'http://foobar/baz/121231.html',
others => 'some other stuff',
},
};
Since the perl world is full of great labour saving devices, it seems
natural that this one is out there somewhere - could you please tell
me if this is so, and if so, where? I've been looking on CPAN and
either found nothing or not undertood what I have seen....
Many thanks in anticipation
Lee
(I posted this to *.moderated too, but not sure it got there, thanks to IE)
------------------------------
Date: Tue, 14 Dec 2004 11:26:00 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Relational databases and tied hashes?
Message-Id: <xtmdnd43KOyEiSLcRVn-tA@adelphia.com>
Lee Goddard wrote:
> Is there a perl module to make life easier with relational,
> linked databases?
>
> For example, three tables, where each has a column acting as
> a unique identifier (*.uid). The "item" table references the
> "stock" table in the item.stock column using the stock.uid column;
> the "item" table references the "image" table in the item.image
> column using the item.uid column.
>
> ITEM TABLE STOCK TABLE IMAGE TABLE
> item.uid stock.uid image.uid
> item.name stock.quantity image.href
> item.price stock.others image.others
> item.stock
> item.image
>
> I'd like a hash for every record I pull out of the "item" table,
> and one that doesn't just give me the "item.stock" uid that is
> there, but does the look-up and give me a hash of the relevant record:
>
> $item->{
> uid => 12,
> name => "My Name",
> price => '',
> stock => {
> uid => 103,
> quantity=> 1,
> others => 'other stuff',
> },
> image => {
> uid => 43,
> href => 'http://foobar/baz/121231.html',
> others => 'some other stuff',
> },
> };
If you're thinking this would take three separate SQL queries, you can
simplify things by taking advantage of SQL's ability to join multiple
tables in a single query:
select item.uid, item.name, item.price, item.stock, item.image,
stock.uid, stock.quantity, stock.others,
image.uid, image.href, image.others
from item, stock, image
where item.uid=? AND
item.stock = stock.uid AND
item.image = image.uid
That will give you "flattened" results, rather than giving you a set of
nested hashes like in your example. You could get nested hashes like this:
# Assume a previously prepare() and execute()d statement in $sth
my $row = $sth->fetchrow_hashref();
my $item = {
'uid' => $row->{'item.uid'},
'name' => $row->{'item.name'},
'price' => $row->{'item.price'},
'stock' => {
'uid' => $row->{'stock.uid'},
'quantity' => $row->{'stock.quantity'},
'others' => $row->{'stock.others'},
},
'image' => {
'uid' => $row->{'image.uid'},
'href' => $row->{'image.href'},
'others' => $row->{'image.others'},
},
};
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: Tue, 14 Dec 2004 17:46:57 +0100
From: Matija Papec <perl@my-header.org>
Subject: Re: Relational databases and tied hashes?
Message-Id: <946ur0lc9f96ru5aimpiafugr43udv1be3@4ax.com>
X-Ftn-To: Lee Goddard
leegee@gmail.com (Lee Goddard) wrote:
>$item->{
> uid => 12,
> name => "My Name",
> price => '',
> stock => {
> uid => 103,
> quantity=> 1,
> others => 'other stuff',
> },
> image => {
> uid => 43,
> href => 'http://foobar/baz/121231.html',
> others => 'some other stuff',
> },
>};
>
>Since the perl world is full of great labour saving devices, it seems
>natural that this one is out there somewhere - could you please tell
>me if this is so, and if so, where? I've been looking on CPAN and
>either found nothing or not undertood what I have seen....
Check for Tie::DBI, it does even table updating for you but avoid it if you
have concerns about the speed.
--
Matija
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 7518
***************************************