[29639] in Perl-Users-Digest
Perl-Users Digest, Issue: 883 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 26 16:09:38 2007
Date: Wed, 26 Sep 2007 13:09:07 -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 Wed, 26 Sep 2007 Volume: 11 Number: 883
Today's topics:
add error to an array or list or hash <rsarpi@gmail.com>
Re: add error to an array or list or hash <ebmarquez@gmail.com>
Re: add error to an array or list or hash <ebmarquez@gmail.com>
Re: Deleting a section of file using perl <paduille.4061.mumia.w+nospam@earthlink.net>
Re: Deleting a section of file using perl xhoster@gmail.com
Guitars for 0$ !!!!! nutsbreaker2@gmail.com
Re: How to read and write a file without open file twic <needpassion@gmail.com>
Re: Perl module for "Instant Messaging" <ignoramus25760@NOSPAM.25760.invalid>
Report to Event Viewer correctly using Win32::EventLog <ebmarquez@gmail.com>
string concatentation vs. interpolation: which one is m <rihad@mail.ru>
Re: string concatentation vs. interpolation: which one <papahuhn@gmx.net>
Re: string concatentation vs. interpolation: which one <simon.chao@fmr.com>
Re: string concatentation vs. interpolation: which one <no@email.com>
Re: string concatentation vs. interpolation: which one <asolkar@gmail.com>
Travel USA travelingwebs1@gmail.com
Re: Upgrading Bundle::CPAN freezes during tests <elsiddik@gmail.com>
Re: why are references so slow ? <bik.mido@tiscalinet.it>
Re: why are references so slow ? xhoster@gmail.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 26 Sep 2007 19:37:45 -0000
From: monk <rsarpi@gmail.com>
Subject: add error to an array or list or hash
Message-Id: <1190835465.990643.167840@w3g2000hsg.googlegroups.com>
Hi all, and thanks in advance.
for example:
open (test.txt, /home/monk) or die $!;
blah blah blah
If it dies $!, How can I output/add that error to an array or hash or
list?
------------------------------
Date: Wed, 26 Sep 2007 20:01:24 -0000
From: ebm <ebmarquez@gmail.com>
Subject: Re: add error to an array or list or hash
Message-Id: <1190836884.162508.179490@50g2000hsm.googlegroups.com>
On Sep 26, 12:37 pm, monk <rsa...@gmail.com> wrote:
> Hi all, and thanks in advance.
>
> for example:
>
> open (test.txt, /home/monk) or die $!;
> blah blah blah
>
> If it dies $!, How can I output/add that error to an array or hash or
> list?
open(test.txt, /home/monk) or $myErrorHash->{'Error'} = $!;
Is that what your looking for. from there you can do something with
that hash and die later on.
------------------------------
Date: Wed, 26 Sep 2007 20:03:00 -0000
From: ebm <ebmarquez@gmail.com>
Subject: Re: add error to an array or list or hash
Message-Id: <1190836980.052391.17930@r29g2000hsg.googlegroups.com>
On Sep 26, 1:01 pm, ebm <ebmarq...@gmail.com> wrote:
> On Sep 26, 12:37 pm, monk <rsa...@gmail.com> wrote:
>
> > Hi all, and thanks in advance.
>
> > for example:
>
> > open (test.txt, /home/monk) or die $!;
> > blah blah blah
>
> > If it dies $!, How can I output/add that error to an array or hash or
> > list?
>
> open(test.txt, /home/monk) or $myErrorHash->{'Error'} = $!;
>
> Is that what your looking for. from there you can do something with
> that hash and die later on.
I wanted to put this
open(test.txt, /home/monk) or $myErrorHash{'Error'} = $!;
I goofed it the first time.
------------------------------
Date: Wed, 26 Sep 2007 04:14:39 -0500
From: "Mumia W." <paduille.4061.mumia.w+nospam@earthlink.net>
Subject: Re: Deleting a section of file using perl
Message-Id: <13fkeq71ehb7h23@corp.supernews.com>
On 09/26/2007 02:24 AM, Ami wrote:
> Hi All,
> I am reading and file and same time modifying it (Inline edit). I
> store a particular position of file on some criteria using tell() and
> than after reading some other stuff, i need to decide, if i want to
> delete the contents of file from previously stored position till
> current position.
> It would be great help, if some one can give me idea/code snippet to
> do it.
> I need a code to delete file contents from one position to another
> position and again continue processing file in same way.
>
> Thanks in advance for your help.
> Regards,
>
Inline editing doesn't mix too well with seek() and tell(), so you'll
probably have to redesign the program to not use inline editing.
If you have a line-oriented file, Tie::File is a great way to make a
file look like an array of lines; you can then use array operations on
that file and delete groups of lines at will.
------------------------------
Date: 26 Sep 2007 16:08:34 GMT
From: xhoster@gmail.com
Subject: Re: Deleting a section of file using perl
Message-Id: <20070926120836.471$CP@newsreader.com>
Ami <ver_amitabh@yahoo.com> wrote:
> Hi All,
> I am reading and file and same time modifying it (Inline edit).
By that do you mean -i (or $^I) ?
> I
> store a particular position of file on some criteria using tell() and
> than after reading some other stuff, i need to decide, if i want to
> delete the contents of file from previously stored position till
> current position.
Can you just delay printing that chunk, storing it in memory instead,
until you make that decision? Then either print it or discard it. If you
can't do it this way, rather than with tell or whatever, then I think that
trying to use -i is a mistake.
> It would be great help, if some one can give me idea/code snippet to
> do it.
> I need a code to delete file contents from one position to another
> position and again continue processing file in same way.
See the implementation of Tie::File. It is not easy, and will probably
be slower than molasses.
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: Wed, 26 Sep 2007 10:52:41 -0700
From: nutsbreaker2@gmail.com
Subject: Guitars for 0$ !!!!!
Message-Id: <1190829161.964778.213800@g4g2000hsf.googlegroups.com>
http://free-guitars.blogspot.com/
------------------------------
Date: Wed, 26 Sep 2007 11:56:16 -0700
From: mike <needpassion@gmail.com>
Subject: Re: How to read and write a file without open file twice? Thanks in advance.
Message-Id: <1190832976.247447.17560@d55g2000hsg.googlegroups.com>
cool!
Guys thanks a lot.
------------------------------
Date: Wed, 26 Sep 2007 08:17:54 -0500
From: Ignoramus25760 <ignoramus25760@NOSPAM.25760.invalid>
Subject: Re: Perl module for "Instant Messaging"
Message-Id: <lsadnWtp2IOfwWfbnZ2dnUVZ_qTinZ2d@giganews.com>
On Tue, 25 Sep 2007 04:16:25 -0000, Todd Wade <waveright@gmail.com> wrote:
> On Sep 24, 1:05 pm, Ignoramus3778 <ignoramus3...@NOSPAM.3778.invalid>
> wrote:
>> I want to write a bot (think IRC bot) that would talk to people over
>> messengers such as AOL, Yahoo, ICQ, Google Talk etc. The bot is
>> "Splotchy Artificial Intelligence robot" from algebra.com. I know that
>> there are perl modules that enable individual messengers. What I want
>> to find is a module that would encompass all of them, where I set up
>> my individual IDs in the config and then just let it chat with people.
>>
>> Any suggestions?
>
> Pidgin's libpurple should work for you. It provides a single API for
> many IM networks, including the ones you mentioned above:
>
> http://developer.pidgin.im/doxygen/dev/html/perl-howto.html
Very nice! I use Pidgin all the time for human-to-human messaging. If
I can plug in like that (I did look at the web page) it would be
awesome. I think that that stuff needs a higher level abstraction than
what I have seen, but whatever, I can use what is available.
i
------------------------------
Date: Wed, 26 Sep 2007 11:58:12 -0700
From: ebm <ebmarquez@gmail.com>
Subject: Report to Event Viewer correctly using Win32::EventLog
Message-Id: <1190833092.376749.92760@n39g2000hsh.googlegroups.com>
I'm writing a script that will run as a scheduled task on a win2k
server. I would like the script to log to the Event Viewer on the
server but when I use the Win32::EventLog module I get a bunch of
garbage included in the Event that I log. Is there a away to do this
with so I don't get the garbage...
Event Type: Error
Event Source: Weekly Report Script
Event Category: None
Event ID: 100
Date: 09/26/2007
Time: 11:56:56 AM
User: N/A
Computer: LVEPL3LX620
Description:
The description for Event ID ( 100 ) in Source ( Weekly Report
Script ) cannot be found. The local computer may not have the
necessary registry information or message DLL files to display
messages from a remote computer. You may be able to use the /
AUXSOURCE= flag to retrieve this description; see Help and Support for
details. The following information is part of the event: This is a
Test Error......
------
script:
use Win32::EventLog;
my $Type = "ERROR";
my $IDNum = 100;
my $Description = "This is a Test Error.....";
chomp( $Type, $IDNum, $Description );
my %Event = (
Length => NULL,
RecordNumber => NULL,
TimeGenerated => NULL,
EventID => $IDNum,
Category => NULL,
Source => "Weekly Report Script",
Strings => $Description,
);
if ( uc($Type) eq "ERROR" ) {
$Event{'EventType'} = EVENTLOG_ERROR_TYPE;
}
elsif ( uc($Type) eq "WARN" ) {
$Event{'EventType'} = EVENTLOG_WARNING_TYPE;
}
elsif ( uc($Type) eq "INFO" ) {
$Event{'EventType'} = EVENTLOG_INFORMATION_TYPE;
}
elsif ( uc($Type) eq "AUDIT" ) {
$Event{'EventType'} = EVENTLOG_AUDIT_SUCCESS;
}
else {
$Event{'EventType'} = EVENTLOG_AUDIT_FAILURE;
}
my $LogEvent = Win32::EventLog->new("Application")
or die "Can't open Application Event Log to enter $Description\n";
$LogEvent->Report( \%Event ) or die($!);
$LogEvent->Close();
------------------------------
Date: Wed, 26 Sep 2007 09:42:11 -0700
From: rihad <rihad@mail.ru>
Subject: string concatentation vs. interpolation: which one is more optimal?
Message-Id: <1190824931.665621.151990@50g2000hsm.googlegroups.com>
Programming Perl (The Camel Book) states that "String concatenation is
also implied by the interpolation that happens in double-quoted
strings."
print $a . ' is equal to ' . $b . ".\n"; # dot operator
print "$a is equal to $b.\n"; # interpolation
Can someone experienced in Perl source code confirm that they are
identical in terms of raw speed and memory use or not? The second one
is much cooler, and if so, I'm going to get rid of concatenation
altogether. (I'm not even considering the list variant separated by
commas, which is suboptimal).
------------------------------
Date: Wed, 26 Sep 2007 19:16:16 +0200
From: papahuhn <papahuhn@gmx.net>
Subject: Re: string concatentation vs. interpolation: which one is more optimal?
Message-Id: <5lvif1Fal3buU1@mid.dfncis.de>
rihad schrieb:
> Programming Perl (The Camel Book) states that "String concatenation is
> also implied by the interpolation that happens in double-quoted
> strings."
>
> print $a . ' is equal to ' . $b . ".\n"; # dot operator
> print "$a is equal to $b.\n"; # interpolation
>
> Can someone experienced in Perl source code confirm that they are
> identical in terms of raw speed and memory use or not? The second one
> is much cooler, and if so, I'm going to get rid of concatenation
> altogether. (I'm not even considering the list variant separated by
> commas, which is suboptimal).
>
time perl -e '$a=$b=303; print "$a $b" for 1..39999999' > /dev/null
real 0m14.500s
user 0m14.460s
sys 0m0.022s
time perl -e '$a=$b=303; print $a." ".$b for 1..39999999' > /dev/null
real 0m12.111s
user 0m12.081s
sys 0m0.014s
------------------------------
Date: Wed, 26 Sep 2007 17:51:11 -0000
From: it_says_BALLS_on_your forehead <simon.chao@fmr.com>
Subject: Re: string concatentation vs. interpolation: which one is more optimal?
Message-Id: <1190829071.130501.36710@22g2000hsm.googlegroups.com>
On Sep 26, 1:16 pm, papahuhn <papah...@gmx.net> wrote:
> rihad schrieb:
>
> > Programming Perl (The Camel Book) states that "String concatenation is
> > also implied by the interpolation that happens in double-quoted
> > strings."
>
> > print $a . ' is equal to ' . $b . ".\n"; # dot operator
> > print "$a is equal to $b.\n"; # interpolation
>
> > Can someone experienced in Perl source code confirm that they are
> > identical in terms of raw speed and memory use or not? The second one
> > is much cooler, and if so, I'm going to get rid of concatenation
> > altogether. (I'm not even considering the list variant separated by
> > commas, which is suboptimal).
>
> time perl -e '$a=$b=303; print "$a $b" for 1..39999999' > /dev/null
> real 0m14.500s
> user 0m14.460s
> sys 0m0.022s
>
> time perl -e '$a=$b=303; print $a." ".$b for 1..39999999' > /dev/null
>
> real 0m12.111s
> user 0m12.081s
> sys 0m0.014s
it probably depends on the length of the string as well. i just wanted
to add the third option of passing print a list:
bash-2.03$ time perl -e '$x=$y=303; print "$x $y" for 1..16777216' > /
dev/null
real 0m17.710s
user 0m17.590s
sys 0m0.002s
bash-2.03$ time perl -e '$x=$y=303; print $x." ".$y for 1..16777216'
> /dev/null
real 0m17.115s
user 0m17.001s
sys 0m0.053s
bash-2.03$ time perl -e '$x=$y=303; print $x," ",$y for 1..16777216'
> /dev/null
real 1m18.498s
user 1m18.310s
sys 0m0.073s
MUCH slower for some reason...thoughts?
------------------------------
Date: Wed, 26 Sep 2007 20:32:51 +0100
From: Brian Wakem <no@email.com>
Subject: Re: string concatentation vs. interpolation: which one is more optimal?
Message-Id: <5lvqf3FaqjsgU1@mid.individual.net>
papahuhn wrote:
> rihad schrieb:
>> Programming Perl (The Camel Book) states that "String concatenation is
>> also implied by the interpolation that happens in double-quoted
>> strings."
>>
>> print $a . ' is equal to ' . $b . ".\n"; # dot operator
>> print "$a is equal to $b.\n"; # interpolation
>>
>> Can someone experienced in Perl source code confirm that they are
>> identical in terms of raw speed and memory use or not? The second one
>> is much cooler, and if so, I'm going to get rid of concatenation
>> altogether. (I'm not even considering the list variant separated by
>> commas, which is suboptimal).
>>
>
> time perl -e '$a=$b=303; print "$a $b" for 1..39999999' > /dev/null
> real 0m14.500s
> user 0m14.460s
> sys 0m0.022s
>
> time perl -e '$a=$b=303; print $a." ".$b for 1..39999999' > /dev/null
>
> real 0m12.111s
> user 0m12.081s
> sys 0m0.014s
I found almost no difference:
$ time perl -e '$a=$b=303; print $a." ".$b for 1..39999999' > /dev/null
real 0m9.109s
user 0m9.095s
sys 0m0.012s
$ time perl -e '$a=$b=303; print "$a $b" for 1..39999999' > /dev/null
real 0m9.007s
user 0m8.997s
sys 0m0.010s
And as another poster has pointed out, using a list is very slow by
comparison:
$ time perl -e '$a=$b=303; print $a," ",$b for 1..39999999' > /dev/null
real 0m31.457s
user 0m31.438s
sys 0m0.018s
--
Brian Wakem
------------------------------
Date: Wed, 26 Sep 2007 12:46:32 -0700
From: Mahesh Asolkar <asolkar@gmail.com>
Subject: Re: string concatentation vs. interpolation: which one is more optimal?
Message-Id: <1190835992.101344.72740@k79g2000hse.googlegroups.com>
On Sep 26, 9:42 am, rihad <ri...@mail.ru> wrote:
> Programming Perl (The Camel Book) states that "String concatenation is
> also implied by the interpolation that happens in double-quoted
> strings."
>
> print $a . ' is equal to ' . $b . ".\n"; # dot operator
> print "$a is equal to $b.\n"; # interpolation
>
> Can someone experienced in Perl source code confirm that they are
> identical in terms of raw speed and memory use or not? The second one
> is much cooler, and if so, I'm going to get rid of concatenation
> altogether. (I'm not even considering the list variant separated by
> commas, which is suboptimal).
>From the benchmark below, it looks like interpolation and
concatenation come pretty close.
-------------------
#!/usr/bin/perl
use strict;
use warnings;
no warnings 'syntax';
use Benchmark qw 'cmpthese';
cmpthese 2000000 => {
'interp' => '$x=$y=303; $z = "$x $y"',
'concat' => '$x=$y=303; $z = $x . " " . $y',
'listjn' => '$x=$y=303; $z = $x," ",$y',
};
-------------- Results -------------------
Rate concat interp listjn
concat 1428571/s -- -1% -56%
interp 1438849/s 1% -- -56%
listjn 3278689/s 130% 128% --
------------------
I usually use one of the two that suits the most. When there is a
really long line involved, I tend to use the concatenation operator so
that I can break the line into multiple shorter lines. Interpolation
is fine in short lines.
HTH,
Mahesh.
------------------------------
Date: Wed, 26 Sep 2007 17:59:16 -0000
From: travelingwebs1@gmail.com
Subject: Travel USA
Message-Id: <1190829556.014952.238600@50g2000hsm.googlegroups.com>
http://world-traveling-destinations.blogspot.com/
------------------------------
Date: Wed, 26 Sep 2007 11:42:20 -0000
From: elsiddik <elsiddik@gmail.com>
Subject: Re: Upgrading Bundle::CPAN freezes during tests
Message-Id: <1190806940.516208.91430@w3g2000hsg.googlegroups.com>
I'm having here the same problem tho.
/usr/bin/perl5.8.7 "-MExtUtils::MY" -e "MY->fixin(shift)" blib/script/
cpan
Manifying blib/man1/cpan.1
Manifying blib/man3/CPAN.3pm
Manifying blib/man3/CPAN::Admin.3pm
Manifying blib/man3/CPAN::Tarzip.3pm
Manifying blib/man3/CPAN::Debug.3pm
Manifying blib/man3/CPAN::HandleConfig.3pm
Manifying blib/man3/CPAN::Queue.3pm
Manifying blib/man3/CPAN::Version.3pm
Manifying blib/man3/CPAN::Kwalify.3pm
Manifying blib/man3/CPAN::API::HOWTO.3pm
Manifying blib/man3/CPAN::Nox.3pm
Manifying blib/man3/CPAN::FirstTime.3pm
/usr/bin/make -- OK
Running make test
PERL_DL_NONLAZY=1 /usr/bin/perl5.8.7 "-MExtUtils::Command::MM" "-e"
"test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/00signature.......ok
1/1 skipped: various reasons
t/01loadme..........ok
t/02nox.............ok
t/03pkgs............ok 1/11
it keeps hanging...
zaher el siddik
On Sep 26, 11:45 am, Matthew Cline <khym.cha...@gmail.com> wrote:
> While using "perl -MCPAN -eshell" to install some Perl packages, I was
> told that there was a new version of CPAN that I could upgrade to. I
> try to upgrade, and everything goes fine until it gets to the tests:
>
> /usr/bin/make -- OK
> Running make test
> PERL_DL_NONLAZY=1 /usr/bin/perl5.8.8 "-MExtUtils::Command::MM" "-e"
> "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
> t/00signature.......ok
> 1/1 skipped: various reasons
> t/01loadme..........ok
> t/02nox.............ok
> t/03pkgs............ok 1/11
>
> And it just freezes at "t/03pkgs............ok 1/11". It's not using
> up any CPU, so it's not an infinite loop, but other than that I have
> no clue. I'm using perl 5.8.8
>
> Thanks in advance.
------------------------------
Date: Wed, 26 Sep 2007 12:41:16 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: why are references so slow ?
Message-Id: <thdkf35jk4o4fr9slrh9280c96v6itpefj@4ax.com>
On Wed, 26 Sep 2007 09:03:58 -0000, Brian McCauley
<nobull67@gmail.com> wrote:
>I'm not sure what this has to do with references but subroutine
>calling it expensive in Perl. As are constructing and unpacking
>argument lists.
>
>> Now i am at a point where i want to use recursion, and perl says its even=
> a deep
>> recursion.
>
>If you want to use recursion I don't think you can do it without
>subroutines. You'd have to refactor your code to be iterative.
(Mostly as an aside) if the recursion can be cast in the form of tail
recursion than much hassle can be eliminated, but existing perls
unfortunately don't handle it natively so one has to take care of that
"manually" with *magic* goto()s.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: 26 Sep 2007 16:39:01 GMT
From: xhoster@gmail.com
Subject: Re: why are references so slow ?
Message-Id: <20070926123902.853$4b@newsreader.com>
Daniel =?UTF-8?B?RMO8bmtlcg==?= <dduenker@uni-koblenz.de> wrote:
>
> Wow thanks, that's a very interesting tool, and of course you are right,
> there are still lot's of inefficient things in my script, but it seems
> that the slowest part's are actually really referencing and
> dereferencing, as for example:
> 4455 3.53946 3.40000 133: return \%pixels;
> which is the part that takes the most time.
How do you know it is the reference, rather than the return, that is
taking the time? You could separate them into two different lines:
my $foo=\%pixels;
return $foo;
Also, I don't find Devel::SmallProf to be particularly reliable. Small
errors in its null compensation methods can lead to substantial spurious
timings.
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: 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 883
**************************************