[30305] in Perl-Users-Digest
Perl-Users Digest, Issue: 1548 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 16 14:09:49 2008
Date: Fri, 16 May 2008 11:09:14 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 16 May 2008 Volume: 11 Number: 1548
Today's topics:
Re: arrow key bindings in perl debugger mode (Jens Thoms Toerring)
DONE: write 10 files <ela@yantai.org>
initialize object permanently (only once) <yingun@gmail.com>
Re: initialize object permanently (only once) <1usa@llenroc.ude.invalid>
Re: initialize object permanently (only once) xhoster@gmail.com
Re: Need ideas on how to make this code faster than a s <rvtol+news@isolution.nl>
Re: Need ideas on how to make this code faster than a s <g.etly@bent-INVALID-sys.com>
Re: Need ideas on how to make this code faster than a s <jurgenex@hotmail.com>
Re: Need ideas on how to make this code faster than a s <g.etly@bent-INVALID-sys.com>
Re: Need ideas on how to make this code faster than a s <nospam-abuse@ilyaz.org>
Re: Need ideas on how to make this code faster than a s <uri@stemsystems.com>
Re: Newsgroup Markup. Was Re: Perl DBI Module: SQL quer <RedGrittyBrick@SpamWeary.foo>
Re: Perl 6 <benkasminbullock@gmail.com>
Re: Permissions on a file <bill@ts1000.us>
Re: Questions on scalar references in general, substr a <bugbear@trim_papermule.co.uk_trim>
Re: Questions on scalar references in general, substr a <ben@morrow.me.uk>
Re: Questions on scalar references in general, substr a <uri@stemsystems.com>
Simple problem with Email::Address <bernie@fantasyfarm.com>
write 10 files <ela@yantai.org>
Re: write 10 files <1usa@llenroc.ude.invalid>
Re: write 10 files <ben@morrow.me.uk>
Re: write 10 files <ela@yantai.org>
Re: write 10 files <bill@ts1000.us>
Re: write 10 files <ela@yantai.org>
Re: write 10 files <devnull4711@web.de>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 16 May 2008 15:20:08 GMT
From: jt@toerring.de (Jens Thoms Toerring)
Subject: Re: arrow key bindings in perl debugger mode
Message-Id: <695n18F30skjsU1@mid.uni-berlin.de>
Andrew DeFaria <Andrew@defaria.com> wrote:
> [-- text/plain, encoding 7bit, charset: ISO-8859-1, 17 lines --]
> Jens Thoms Toerring wrote:
> > You should be aware that using .inputrc in your home directory also
> > sets the keybindings also for all other programs that use
> > the readline library (e.g. xterm). The simplest way around that is
> > probably to create an alias like (bash style)
> >
> > alis pd='INPUTRC=~/.perldinputrc perl -d'
> >
> > so that the INPUTRC variable gets only set to the file with eybindings
> > for the debugger, named here .perldinputrc in your home directory,
> > when you start perl in debug mode with the new "command" 'pd'.
> Why in the world would I want the Perl debugger to behave one way and
> bash another?
Maybe because you want to assign to some function keys an
action that doesn't make sense in an xterm? Like e.g. assigning
the debuggers 'q' command to F12 while the same function key
should emit 'exit' in an xterm?
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
------------------------------
Date: Fri, 16 May 2008 23:23:33 +0800
From: "Ela" <ela@yantai.org>
Subject: DONE: write 10 files
Message-Id: <g0k8tr$94f$1@ijustice.itsc.cuhk.edu.hk>
> use strict;
> use warnings;
>
> my @fh;
> my $k = 0;
>
> open $fh[$k],'>','/tmp/test.txt' or die $!;
> print {$fh[$k]} "Hello\n" or die $!;
> close $fh[$k] or die $!;
>
> Frank
Tested and confirmed to work, but also thank Sinan's great efforts. Also the
reminder from Bill. And lastly, Ben. He always helps me a lot.
------------------------------
Date: Fri, 16 May 2008 03:41:20 -0700 (PDT)
From: Keenlearner <yingun@gmail.com>
Subject: initialize object permanently (only once)
Message-Id: <54ff01f2-a65b-43aa-82bc-71695bf544ca@1g2000prg.googlegroups.com>
Hello, I am using Wordnet::QueryData which allow access to a very huge
dictionary data. The initialization of object
my $wn = WordNet::QueryData->new;
took
2 wallclock secs ( 2.36 usr + 0.07 sys = 2.43 CPU)
Then the subsequent request for the data is exetremely fast
For the lines below took
0 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)
print "Synset: ", join(", ", $wn->querySense("cat#n#7", "syns")),
"\n";
print "Hyponyms: ", join(", ", $wn->querySense("cat#n#1", "hypo")),
"\n";
print "Parts of Speech: ", join(", ", $wn->querySense("run")), "\n";
print "Senses: ", join(", ", $wn->querySense("run#v")), "\n";
print "Forms: ", join(", ", $wn->validForms("lay down#v")), "\n";
print "Noun count: ", scalar($wn->listAllWords("noun")), "\n";
print "Antonyms: ", join(", ", $wn->queryWord("dark#n#1", "ants")),
"\n";
I
am developing a web application, is there a way to make the
initialization of object permanently in memory ? I tried to use the
Storable module. But that only give me a little increase in
performance. Anybody's idea is very much appreciated, Thank you.
William
Send instant messages to your online friends http://uk.messenger.yahoo.com
------------------------------
Date: Fri, 16 May 2008 10:47:28 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: initialize object permanently (only once)
Message-Id: <Xns9AA04514FB5FFasu1cornelledu@127.0.0.1>
Keenlearner <yingun@gmail.com> wrote in
news:54ff01f2-a65b-43aa-82bc-71695bf544ca@1g2000prg.googlegroups.com:
> I am developing a web application, is there a way to make the
> initialization of object permanently in memory ? I tried to use the
> Storable module. But that only give me a little increase in
> performance. Anybody's idea is very much appreciated, Thank you.
Short of using mod_perl or FastCGI, I don't think so.
Incidentally, it looks like there is a bug in this module:
# Perform all initialization for new WordNet class instance
sub _initialize#
{
my $self = shift;
...
my $old_separator = $/;
$/ = "\n";
...
# Return setting of input record separator
$/ = $old_separator;
}
Shouldn't the setting and the re-setting of $/ be replaced with
local $/ = "\n";
I see potential problems with _initialize in a persistent environment.
Could someone please confirm?
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
------------------------------
Date: 16 May 2008 18:08:21 GMT
From: xhoster@gmail.com
Subject: Re: initialize object permanently (only once)
Message-Id: <20080516140823.208$8Y@newsreader.com>
Keenlearner <yingun@gmail.com> wrote:
> Hello, I am using Wordnet::QueryData which allow access to a very huge
> dictionary data. The initialization of object
> my $wn = WordNet::QueryData->new;
>
> took
> 2 wallclock secs ( 2.36 usr + 0.07 sys = 2.43 CPU)
>
> Then the subsequent request for the data is exetremely fast
>
...
> print "Noun count: ", scalar($wn->listAllWords("noun")), "\n";
This one is problematic (i.e. slow) with the method I will outline below.
So I commented it out and tested only the other requests.
> I
> am developing a web application, is there a way to make the
> initialization of object permanently in memory ?
Under straightforward CGI, the process ends when the request is done, so
the object ends with it. So the real answer here is to use mod_perl
or one of the other ways of running CGI with a persistent perl process.
> I tried to use the
> Storable module. But that only give me a little increase in
> performance. Anybody's idea is very much appreciated, Thank you.
Again, the best answer is almost certainly to use mod_perl or the like.
But just for kicks, I made it work with DBM::Deep, version 0.983. This way
the data is stored on disk and only the parts actually used are read into
memory. As alluded to above, listAllWords defeats the purpose of this as
it goes through so much stuff, causing to be read into memory.
First one needs to prepare the database, to be held in "file.dbm". This
only needs to be done one time, or whenever the data files are updated:
perl -e 'use WordNet::QueryData; my $x= WordNet::QueryData->new(); \
delete $x->{data_fh}; use DBM::Deep; my $h=DBM::Deep->new("file.dbm"); \
$h->{foo}=$x;'
Once that is done, you can replace "my $wn = WordNet::QueryData->new;"
with:
use DBM::Deep;
my $x=DBM::Deep->new("file.dbm")->{foo};
my $wn={}; %$wn=%$x; #convert the top level to regular hash
#(so it can be blessed)
delete $wn->{data_fh}; # I don't know why this is necessary
# as this entry should not be here to begin with
bless $wn, 'WordNet::QueryData';
$wn->openData; ## restore contents of $wn->{data_fh)
And from here use $wn just as before. This is very similar to the
"Storable" method demonstrated a few months ago in comp.lang.perl.modules,
except using this method data is read from disk only when requested.
Here are timings on my machine for your "subsequent requests", except for
the listAllWords ones:
original:
0:01.73
Storable
0:00.50
DBM::Deep
0:00.07
I have compared the output of all methods and they are identical, but that
doesn't constitute a rigorous test, so use with caution.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: Fri, 16 May 2008 09:54:51 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Need ideas on how to make this code faster than a speeding turtle
Message-Id: <g0jlnk.1kg.1@news.isolution.nl>
chadda@lonemerchant.com schreef:
> I know I shouldn't critize free help, but you seem to have some anger
> management issues.
*plonk*
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Fri, 16 May 2008 09:08:03 -0700
From: "Gordon Etly" <g.etly@bent-INVALID-sys.com>
Subject: Re: Need ideas on how to make this code faster than a speeding turtle
Message-Id: <695pr4F30lr24U1@mid.individual.net>
Uri Guttman wrote:
> Gordon Etly <getly@bentsys-INVALID.com> writes:
[please don't left pad quoted text with spaces]
> > chadda@lonemerchant.com wrote:
> > > On May 15, 1:37 pm, Uri Guttman <u...@stemsystems.com> wrote:
> > > chadda <cha...@lonemerchant.com> writes:
> > > > i have to know if you could write this mess any slower? you are
> > > > doing
> > > > everything possible to slow you down.
> > > I know I shouldn't critize free help, but you seem to have some
> > > anger management issues.
> > He seems to constantly come across this way. I really wish he could
> > see things from other points of view.
> > ...
> as usual, no help from you.
I'm just pointing out what is. It's you who keep bringing this upon
yourself. You are constantly rude and arrogant to people, then you
wonder why people sometimes post back, like the OP did. If you can't
handle receiving comments about what you post, then don't post. If you
can't take it, don't dish it out.
> > As a simple answer, take a look at LWP:UserAgent
> > (http://search.cpan.org/~gaas/libwww-perl-5.812/lib/LWP/UserAgent.pm),
> > as a good start in the right direction.
> which i already told him and we have already improved his code a good
> deal. try to keep up.
I would think someone who has been on UseNet as logn as you would know
that posts don't always come down at the same time (or order) from every
server. Case in point, I had not seen such a post mentioning it until
later on.
--
G.Etly
------------------------------
Date: Fri, 16 May 2008 16:16:48 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Need ideas on how to make this code faster than a speeding turtle
Message-Id: <lrcr24t02ksg82aedvj12g88tdnthjjmuu@4ax.com>
"Gordon Etly" <g.etly@bent-INVALID-sys.com> wrote:
>I'm just pointing out what is. It's you who keep bringing this upon
>yourself. You are constantly rude and arrogant to people, then you
Changing your identity again because everyone filtered you?
jue
------------------------------
Date: Fri, 16 May 2008 09:17:45 -0700
From: "Gordon Etly" <g.etly@bent-INVALID-sys.com>
Subject: Re: Need ideas on how to make this code faster than a speeding turtle
Message-Id: <695qdaF301743U1@mid.individual.net>
Jürgen Exner wrote:
> "Gordon Etly" <getly@bentsys-INVALID.com> wrote:
> > He seems to constantly come across this way. I really wish he could
> > see things from other points of view.
> I guess everyone had filtered you so you had to create a new identity
I have not changed my identity. My name is Gordon Etly. I have not
changed that part, nor made any attempt to hide it, so your statement is
false.
I happen to be a sys op for the company I work for, including our mail
server, so I am able to add entries to /etc/aliases (which I commonly
use to public variants of my main email address that any unwanted
mailings can be easily stopped.) I've never seen any rule saying "never
change your email field", as that is anyone's right.
> > As a simple answer, take a look at LWP:UserAgent
> > (http://search.cpan.org/~gaas/libwww-perl-5.812/lib/LWP/UserAgent.pm),
> > as a good start in the right direction.
> Yeah, it's easy enough to copy what other people had mentioned
> already.
I had not seen that mentioned at all before I posted. Funny, I see you
and your fellows do exactly this all the time (posting essentially the
same answer that was already given by someone else), but now it's
suddenly a bad thing. Please make up your minds.
In this case, there were no replies mentioning LWP::UserAgent. Uri did
mention LWP very briefly, but LWP has several modules. I was more
specific.
--
G.Etly
------------------------------
Date: Fri, 16 May 2008 07:17:30 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Need ideas on how to make this code faster than a speeding turtle
Message-Id: <g0jcea$2vch$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
Uri Guttman
<uri@stemsystems.com>], who wrote in article <x7prrn9r54.fsf@mail.sysarch.com>:
> better but forking off lynx is still slow. LWP should be much faster. if
> you want speed (and with the data size you have, you want it), use LWP.
This may depend on many parameters, but the overhead of system()ing
may be quite low. The overhead of opening a new HTTP connection for
each line may be larger. LWP will have a chance to use persistent
connections...
Yours,
Ilya
------------------------------
Date: Fri, 16 May 2008 16:18:20 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Need ideas on how to make this code faster than a speeding turtle
Message-Id: <x7tzgy1aus.fsf@mail.sysarch.com>
>>>>> "IZ" == Ilya Zakharevich <nospam-abuse@ilyaz.org> writes:
IZ> [A complimentary Cc of this posting was sent to
IZ> Uri Guttman
IZ> <uri@stemsystems.com>], who wrote in article <x7prrn9r54.fsf@mail.sysarch.com>:
>> better but forking off lynx is still slow. LWP should be much faster. if
>> you want speed (and with the data size you have, you want it), use LWP.
IZ> This may depend on many parameters, but the overhead of
IZ> system()ing may be quite low. The overhead of opening a new HTTP
IZ> connection for each line may be larger. LWP will have a chance to
IZ> use persistent connections...
i highly doubt forking lynx and it doing a fetch with passing the page
back via a pipe would be faster than a direct call to lwp and getting
the page in ram. it would have to be a very odd system for the lynx
solution to be faster.
and lynx would have to always open a new connection as forked procs have
no memory.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Fri, 16 May 2008 11:46:21 +0100
From: RedGrittyBrick <RedGrittyBrick@SpamWeary.foo>
Subject: Re: Newsgroup Markup. Was Re: Perl DBI Module: SQL query where there is space in field name
Message-Id: <482d65fe$0$10640$fa0fcedb@news.zen.co.uk>
Peter J. Holzer wrote:
> On 2008-05-13 13:49, RedGrittyBrick <RedGrittyBrick@SpamWeary.foo> wrote:
>> "l) I'd prefer plain text markup of the sort used by GrutaTxt or
>> ASCIIDOC but simplified. That way I could embed tables that work well
>> in plain-text newsreaders but would also look pretty in any
>> newsreader that supported that format." - RGB
>>
>> "That would be nice, but wouldn't you have the same battle on your hands
>> that those pushing html currently do?" - szr
> [...]
>> This posting is written in a form compatible with Grutatxt. In theory a
>> newreader could render it with the headings in various fonts and sizes,
>> with the bullet lists shown with proper bullet characters and with the
>> tables displayed in some more pleasing form..
>
> If it recognizes the page as Grutatxt. How would it do that?
I don't know, maybe using a header 'Content-type = text/structured'?
Don't forget many (most?) newsreaders already recognise *asterisks*
/obliques/ and _underscores_ without requiring any special indicators.
Ditto for lines starting with ">". Is there any *technical* reason they
shouldn't look out for other markup too?
> The
> mime-confoming way would be to use format=grutatext similar to
> format=flowed.
OK.
>
>> Is there any anti-HTML-in-newsgroups reader out there who finds the
>> formatting and markup of this posting really objectionable?
>
> I find the quoting objectionable. It's difficult to see that the two
> quotes are quotes from previous messages in the same thread.
>
True. That would need addressing.
I did wonder if I should have done it thus:
Fred said:
"blah blah
blah blah"
Mary retorted:
"pardon?"
But I guess a usenet-structured text format would probably retain the
existing quoting conventions.
Rather than thinking of a formal format maybe it would be best to think
off somehow adding to the *asterisk* /oblique/ _underscore_ set of
loosely respected conventions.
It's not like I have some well thought out proposal here, this is just
thinking out aloud :-)
--
RGB
------------------------------
Date: Fri, 16 May 2008 13:12:54 +0000 (UTC)
From: Ben Bullock <benkasminbullock@gmail.com>
Subject: Re: Perl 6
Message-Id: <g0k18l$m38$1@ml.accsnet.ne.jp>
On Wed, 14 May 2008 21:59:10 +0000, John Bokma wrote:
> I wonder why people are so eager to get Perl6.
I suppose the same reason people pay more money to get the latest TV or
camera or something? Or the same reason people buy a newspaper even
though they bought one the day before? People are always interested in
new things.
> It's done when it's done.
If you try to sound too nonchalant about it, I wonder why you aren't
interested. If you use Perl, it's natural to wonder about the next major
version. Your attitude is just a bit weird.
> What's missing in Perl5? A lot of Perl6 features are available via
> modules. Personally I see Perl6 more like a new language than more of
> the same (Perl). If you want to bite your teeth in a new language, there
> are plenty to pick from.
So you're telling people to pick a new language rather than Perl, such as
PHP, Python, Ruby, or JavaScript?
I discovered that Perl six has a funny new regex operator \N which
replaces . and no more /s and /m, and the . now equals [.\n]. Yes I would
like to try this new language out, what is so strange about that?
> And last time I checked, there was plenty of room for help *with* Perl.
> If I have more time available, I'll want to look into that. From what
> I've read so far, you don't have to be a rocket scientist to actually
> help with Perl6, there are plenty of things to do that require just some
> good programming skills.
I didn't read this information, so perhaps you can tell us where we can
read it.
------------------------------
Date: Fri, 16 May 2008 02:12:29 -0700 (PDT)
From: Bill H <bill@ts1000.us>
Subject: Re: Permissions on a file
Message-Id: <4877909b-3def-4c64-aeab-67ef9bb9cd43@p25g2000hsf.googlegroups.com>
> The problem is that I need to be able to delete this file remotely
> using FTP and the script generate a new version every now and then. I
> need teh script to make the file deleteable. How do I do this?
> I tried chmod 0777,'remote.txt' and it spews out errors.
>
> K.
I believe your problem is not a perl issue but a permission issue. The
script is running under a webmaster or other account and the file
created is owned by that creator, yet your ftp access is under a
different account name. If you have shell access, do a ls -l on that
directory to see who is the owner / group, that is who you need to be
to delete it. If you have ftp access as the server admin (versus the
webmaster) you can delete the file then (at least this has been my
experience).
I run into this all the time when a client gives me ftp access to
their website and gives me a webmaster account and wants me to update
their stuff that they posted using a different account. Interesting
thing I have seen is that I can most of the time rename what they have
then post my changed files, but can't delete what they have (or
overwrite it).
Back on the perl issue, I did find away around this about 7 / 8 years
ago by using chown on the file after creating it to change who owned
the file from within a perl script.
Bill H
------------------------------
Date: Fri, 16 May 2008 10:11:46 +0100
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: Questions on scalar references in general, substr and regular expression engine in particular
Message-Id: <8IydnSdB5tpO0rDVnZ2dnUVZ8vKdnZ2d@posted.plusnet>
sln@netherlands.co wrote:
> ActiveState perl guidelines state its better to pass by reference for best performance.
>
> Does this apply in the case of SCALARS?
No.
BugBear
------------------------------
Date: Fri, 16 May 2008 12:41:58 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Questions on scalar references in general, substr and regular expression engine in particular
Message-Id: <6h80g5-hf4.ln1@osiris.mauzo.dyndns.org>
Quoth bugbear <bugbear@trim_papermule.co.uk_trim>:
> sln@netherlands.co wrote:
> > ActiveState perl guidelines state its better to pass by reference for
> best performance.
> >
> > Does this apply in the case of SCALARS?
>
> No.
To expand a little: the items in @_ are aliases, not copies, so if you
manipulate them directly you will not be taking a copy. However, as soon
as you do something like
my ($x, $y, $z) = @_;
you've copied all your arguments, and if one of those was a huge great
string you've just done a big memcpy.
Of course, manipulating @_ directly is obscure, and you run the risk of
modifying your arguments unexpectedly. Under normal circumstances (when
you're not expecting to deal with truly enormous strings) taking a copy
is the right thing to do. When it isn't, if you are going to modify the
arguments passed it is probably clearer to make the caller pass a
reference explicitly.
Ben
--
Razors pain you / Rivers are damp
Acids stain you / And drugs cause cramp. [Dorothy Parker]
Guns aren't lawful / Nooses give
Gas smells awful / You might as well live. ben@morrow.me.uk
------------------------------
Date: Fri, 16 May 2008 16:32:39 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Questions on scalar references in general, substr and regular expression engine in particular
Message-Id: <x7prrm1a6w.fsf@mail.sysarch.com>
>>>>> "b" == bugbear <bugbear@trim_papermule.co.uk_trim> writes:
b> sln@netherlands.co wrote:
>> ActiveState perl guidelines state its better to pass by reference for best performance.
>> Does this apply in the case of SCALARS?
b> No.
i beg to differ. when passing around large scalars (e.g. long pieces of
text), passing by ref is better. typically args are copied from @_ and
that will be slower with large scalars. so when i work with large
scalars i tend to pass them by ref. you do have to make sure about
modifications not affecting the original or not caring about that.
but i also don't like giving good advice to sln as he is a troll who
doesn't listen. his xml parser is insane.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Fri, 16 May 2008 13:37:08 -0400
From: Bernie Cosell <bernie@fantasyfarm.com>
Subject: Simple problem with Email::Address
Message-Id: <aahr24dpblvs36fuh7ja9gvdhavod3kn9o@library.airnews.net>
I'm trying to parse an email address and I can't seem to get Email::Address
to work quite.
#!/usr/bin/perl
use strict;
use warnings ;
use Email::Address ;
my $addr = "My Name <myname\@verizon.net>\n" ;
my @addrs = Email::Address::parse($addr) ;
warn scalar(@addrs) ;
Gets me "0" -- it appears not to parse that string, which certainly looks
like a legal email addr to me [am I missing some problem with it?? -- I
actually pulled it out of a file of addresses that sendmail is happily
sending-via]. What am I missing here? THANKS!
/bernie\
--
Bernie Cosell Fantasy Farm Fibers
bernie@fantasyfarm.com Pearisburg, VA
--> Too many people, too few sheep <--
------------------------------
Date: Fri, 16 May 2008 17:45:21 +0800
From: "Ela" <ela@yantai.org>
Subject: write 10 files
Message-Id: <g0jl3m$cj$1@ijustice.itsc.cuhk.edu.hk>
The following codes are not accepted by Perl and even string concatenation
doesn't work. Any suggestions?
#!/usr/bin/perl
$infile = $ARGV[0];
foreach $k (0..10) {
$outfile = $infile . $k;
open (OFP$k, ">$outfile");
}
$i = $size/10000;
print OFP$i "something"; #0-10k, 10-20k, .... 90-100k...
------------------------------
Date: Fri, 16 May 2008 10:41:09 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: write 10 files
Message-Id: <Xns9AA044026E397asu1cornelledu@127.0.0.1>
"Ela" <ela@yantai.org> wrote in
news:g0jl3m$cj$1@ijustice.itsc.cuhk.edu.hk:
> The following codes are not accepted by Perl and even string
> concatenation doesn't work.
Doesn't work is not a good problem description.
> Any suggestions?
See below.
> #!/usr/bin/perl
use strict;
use warnings;
> $infile = $ARGV[0];
> foreach $k (0..10) {
You realize that loops 11 times, right?
> $outfile = $infile . $k;
> open (OFP$k, ">$outfile");
First off, you should check if open succeeded. Second, what makes you
think you can use OFP$k where Perl expects a filehandle.
This looks like a very poor attempt at using symbolic file handles (if
such a thing even exsits, I don't know).
When you find yourself wanting to index something using an integer, you
should use an array.
> }
>
> $i = $size/10000;
> print OFP$i "something"; #0-10k, 10-20k, .... 90-100k...
#!/usr/bin/perl
use strict;
use warnings;
my ($prefix) = @ARGV;
die "No prefix specified\n" unless defined $prefix;
my @out;
for my $i ( 0 .. 9 ) {
my $name = "${prefix}${i}";
if ( open my $fh, '>', $name ) {
push @out_h, { name => $name, handle => $fh };
}
else {
warn "Error opening '$name': $!\n";
}
}
for my $file ( @out ) {
my $handle = $file->{handle};
my $name = $file->{name};
print $handle "This is $name\n";
unless ( close $handle ) {
warn "Error closing '$name': $!";
}
undef $file->{handle};
}
__END__
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
------------------------------
Date: Fri, 16 May 2008 12:46:48 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: write 10 files
Message-Id: <8q80g5-hf4.ln1@osiris.mauzo.dyndns.org>
Quoth "A. Sinan Unur" <1usa@llenroc.ude.invalid>:
> "Ela" <ela@yantai.org> wrote in
> news:g0jl3m$cj$1@ijustice.itsc.cuhk.edu.hk:
>
> > open (OFP$k, ">$outfile");
>
> First off, you should check if open succeeded. Second, what makes you
> think you can use OFP$k where Perl expects a filehandle.
>
> This looks like a very poor attempt at using symbolic file handles (if
> such a thing even exsits, I don't know).
Yes, it does. A filehandle is just an unquoted string, so
open "OFP$k", ">$outfile";
'works', FSVO.
(I'm leaving this bit in just in case anyone gets the wrong idea from
this post... :) )
> When you find yourself wanting to index something using an integer, you
> should use an array.
Ben
--
I touch the fire and it freezes me, [ben@morrow.me.uk]
I look into it and it's black.
Why can't I feel? My skin should crack and peel---
I want the fire back... Buffy, 'Once More With Feeling'
------------------------------
Date: Fri, 16 May 2008 21:37:20 +0800
From: "Ela" <ela@yantai.org>
Subject: Re: write 10 files
Message-Id: <g0k2mm$6d5$1@ijustice.itsc.cuhk.edu.hk>
> Yes, it does. A filehandle is just an unquoted string, so
>
> open "OFP$k", ">$outfile";
>
> 'works', FSVO.
>
> (I'm leaving this bit in just in case anyone gets the wrong idea from
> this post... :) )
Does "works" mean it does not generate error but still cannot achieve the
effect of printing into different files? Because I'm able to open empty
file1, file2, ..., file10 but nothing is printed into them.
------------------------------
Date: Fri, 16 May 2008 07:05:39 -0700 (PDT)
From: Bill H <bill@ts1000.us>
Subject: Re: write 10 files
Message-Id: <2fedc569-ad1c-45a4-8a2b-c19291ce1e8f@d1g2000hsg.googlegroups.com>
On May 16, 5:45=A0am, "Ela" <e...@yantai.org> wrote:
> The following codes are not accepted by Perl and even string concatenation=
> doesn't work. Any suggestions?
>
> #!/usr/bin/perl
>
> $infile =3D $ARGV[0];
> foreach $k (0..10) {
> =A0 =A0 $outfile =3D $infile . $k;
> =A0 =A0 open (OFP$k, ">$outfile");
>
> }
>
> $i =3D $size/10000;
> print OFP$i "something"; #0-10k, 10-20k, .... 90-100k...
Unless $size is always evenly divisible by 10000 then $i will not be
the number you expect it to be (use $i =3D int($size/10000); instead)
and it will never print into one of the file handles you have open.
(for example, $size =3D 11,000 then $i =3D 11000/10000 will equal 1.1, not
the "1" you expect.)
Bill H
------------------------------
Date: Fri, 16 May 2008 22:59:10 +0800
From: "Ela" <ela@yantai.org>
Subject: Re: write 10 files
Message-Id: <g0k7g3$8e3$1@ijustice.itsc.cuhk.edu.hk>
> $i = $size/10000;
> print OFP$i "something"; #0-10k, 10-20k, .... 90-100k...
Unless $size is always evenly divisible by 10000 then $i will not be
the number you expect it to be (use $i = int($size/10000); instead)
and it will never print into one of the file handles you have open.
(for example, $size = 11,000 then $i = 11000/10000 will equal 1.1, not
the "1" you expect.)
Bill H
Yes, u a right. and I've already added int ($size/10000)
------------------------------
Date: Fri, 16 May 2008 17:00:24 +0200
From: Frank Seitz <devnull4711@web.de>
Subject: Re: write 10 files
Message-Id: <695lsgF300ctcU1@mid.individual.net>
Ela wrote:
>>Yes, it does. A filehandle is just an unquoted string, so
>>
>> open "OFP$k", ">$outfile";
>>
>>'works', FSVO.
>>
>>(I'm leaving this bit in just in case anyone gets the wrong idea from
>>this post... :) )
>
> Does "works" mean it does not generate error but still cannot achieve the
> effect of printing into different files? Because I'm able to open empty
> file1, file2, ..., file10 but nothing is printed into them.
use strict;
use warnings;
my @fh;
my $k = 0;
open $fh[$k],'>','/tmp/test.txt' or die $!;
print {$fh[$k]} "Hello\n" or die $!;
close $fh[$k] or die $!;
Frank
--
Dipl.-Inform. Frank Seitz; http://www.fseitz.de/
Anwendungen für Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel
------------------------------
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 V11 Issue 1548
***************************************