[28238] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 9602 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Aug 14 18:06:06 2006

Date: Mon, 14 Aug 2006 15:05:16 -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           Mon, 14 Aug 2006     Volume: 10 Number: 9602

Today's topics:
        [VOTE] Multi-post flagging 'bot <mumia.w.18.spam+nospam.usenet@earthlink.net>
    Re: [VOTE] Publicly flog David Filmer for writing multi <1usa@llenroc.ude.invalid>
    Re: [VOTE] Publicly flog David Filmer for writing multi <john@castleamber.com>
    Re: [VOTE] Publicly flog David Filmer for writing multi <bik.mido@tiscalinet.it>
    Re: [VOTE] Publicly flog David Filmer for writing multi xhoster@gmail.com
    Re: [VOTE] Publicly flog David Filmer for writing multi <john@castleamber.com>
        [VOTE] Publicly flog David Filmer for writing multi-pos <mumia.w.18.spam+nospam.usenet@earthlink.net>
        current directory name in perl <dennishancy@eaton.com>
    Re: current directory name in perl <1usa@llenroc.ude.invalid>
    Re: current directory name in perl <dennishancy@eaton.com>
    Re: current directory name in perl <1usa@llenroc.ude.invalid>
    Re: current directory name in perl <user@example.invalid>
    Re: current directory name in perl <rvtol+news@isolution.nl>
    Re: current directory name in perl axel@white-eagle.invalid.uk
    Re: Failure with perl2exe <sherm@Sherm-Pendleys-Computer.local>
    Re: is it possible to efficiently read a large file? <Mark.Seger@hp.com>
    Re: is it possible to efficiently read a large file? <Mark.Seger@hp.com>
    Re: is it possible to efficiently read a large file? <benmorrow@tiscali.co.uk>
    Re: Is there arithmetic sequence represents? <tzz@lifelogs.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Mon, 14 Aug 2006 18:19:46 GMT
From: "Mumia W." <mumia.w.18.spam+nospam.usenet@earthlink.net>
Subject: [VOTE] Multi-post flagging 'bot
Message-Id: <693Eg.5009$Qf.985@newsread2.news.pas.earthlink.net>

VOTE:

Multi-post flagging 'bot:

Nay



------------------------------

Date: Mon, 14 Aug 2006 18:36:20 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: [VOTE] Publicly flog David Filmer for writing multi-post flagging 'bot
Message-Id: <Xns981F94AD1FD19asu1cornelledu@127.0.0.1>

"Mumia W." <mumia.w.18.spam+nospam.usenet@earthlink.net> wrote in 
news:793Eg.5010$Qf.2216@newsread2.news.pas.earthlink.net:

> VOTE:
> 
> Publicly flog David Filmer for writing multi-post flagging 'bot:
> 
> Yea

In as much as I like burning multi-posted threads along with extensive 
cross-posting to more than 2 groups, I wasn't sure if David's bot in its 
current incarnation was a good idea.

On the other hand, this attempt by yours to create separate VOTE threads 
with an abusive subject line stinks. 

My recommendation to David is to go back to the good old days of 
pointing out in clpmisc questions that have been multi-posted, as he 
becomes aware of them. There is no need to make prescriptive statments 
such as "burn this thread". There is also no need to catch every single 
multi-posted message. Those of us who care will promptly take action. 
Those who don't care are not bothered by giant shouting messages and the 
subsequent trolling.

In any case, Mr W., I won't be hearing from you. Bye.

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://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html



------------------------------

Date: 14 Aug 2006 18:57:10 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: [VOTE] Publicly flog David Filmer for writing multi-post flagging 'bot
Message-Id: <Xns981F8DEDB838Fcastleamber@130.133.1.4>

"A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote:

> "Mumia W." <mumia.w.18.spam+nospam.usenet@earthlink.net> wrote in 
> news:793Eg.5010$Qf.2216@newsread2.news.pas.earthlink.net:
> 
>> VOTE:
>> 
>> Publicly flog David Filmer for writing multi-post flagging 'bot:
>> 
>> Yea
> 
> In as much as I like burning multi-posted threads along with extensive 
> cross-posting to more than 2 groups, I wasn't sure if David's bot in its 
> current incarnation was a good idea.
> 
> On the other hand, this attempt by yours to create separate VOTE threads 
> with an abusive subject line stinks. 
> 
> My recommendation to David is to go back to the good old days of 
> pointing out in clpmisc questions that have been multi-posted, as he 
> becomes aware of them. There is no need to make prescriptive statments 
> such as "burn this thread". There is also no need to catch every single 
> multi-posted message. Those of us who care will promptly take action. 
> Those who don't care are not bothered by giant shouting messages and the 
> subsequent trolling.

second. Moreover, I suggest to use something along the lines of:

You shouldn't post the same message separately to several groups 
(multiposting), see: http://www.cs.tut.fi/~jkorpela/usenet/xpost.html

to explain what's wrong.

Most people who multipost have no idea what "Don't multipost" means :-)

-- 
John Bokma          Freelance software developer
                                &
                    Experienced Perl programmer: http://castleamber.com/


------------------------------

Date: 14 Aug 2006 21:35:02 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: [VOTE] Publicly flog David Filmer for writing multi-post flagging 'bot
Message-Id: <ruj1e2l7rg08k1eveh40vc5ivrhbv3khog@4ax.com>

On Mon, 14 Aug 2006 18:19:47 GMT, "Mumia W."
<mumia.w.18.spam+nospam.usenet@earthlink.net> wrote:

>Publicly flog David Filmer for writing multi-post flagging 'bot:
>
>Yea

Naaah! David Filmer is a good contributor to the group. This is
orthogonal to the fact that I don't like his bot myself. BTW: I'll
never really know when (if) it's disabled, since I already killfiled
it.


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: 14 Aug 2006 20:03:37 GMT
From: xhoster@gmail.com
Subject: Re: [VOTE] Publicly flog David Filmer for writing multi-post flagging 'bot
Message-Id: <20060814161400.095$ZA@newsreader.com>

"Mumia W." <mumia.w.18.spam+nospam.usenet@earthlink.net> wrote:
> VOTE:
>
> Publicly flog David Filmer for writing multi-post flagging 'bot:

I'd rather flog you for starting two new threads to "vote" on
the same thing that was already being adequately discussed in
existing threads.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


------------------------------

Date: 14 Aug 2006 20:14:45 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: [VOTE] Publicly flog David Filmer for writing multi-post flagging 'bot
Message-Id: <Xns981F9B1519B7Ccastleamber@130.133.1.4>

Michele Dondi <bik.mido@tiscalinet.it> wrote:

> On Mon, 14 Aug 2006 18:19:47 GMT, "Mumia W."
> <mumia.w.18.spam+nospam.usenet@earthlink.net> wrote:
> 
>>Publicly flog David Filmer for writing multi-post flagging 'bot:
>>
>>Yea
> 
> Naaah! David Filmer is a good contributor to the group. This is
> orthogonal to the fact that I don't like his bot myself.

Ditto. 

-- 
John Bokma          Freelance software developer
                                &
                    Experienced Perl programmer: http://castleamber.com/


------------------------------

Date: Mon, 14 Aug 2006 18:19:47 GMT
From: "Mumia W." <mumia.w.18.spam+nospam.usenet@earthlink.net>
Subject: [VOTE] Publicly flog David Filmer for writing multi-post flagging 'bot
Message-Id: <793Eg.5010$Qf.2216@newsread2.news.pas.earthlink.net>

VOTE:

Publicly flog David Filmer for writing multi-post flagging 'bot:

Yea




------------------------------

Date: 14 Aug 2006 08:53:07 -0700
From: "dennishancy@eaton.com" <dennishancy@eaton.com>
Subject: current directory name in perl
Message-Id: <1155570786.997753.38140@h48g2000cwc.googlegroups.com>

Is there a function in perl that will tell me the directory name of the
currently running script?

In other words, I want to run the script c:\someDirName\scriptName.exe,
and I want to find a function that will return "c:\someDirName\".

I found tellDir and seekDir, but I am either using it the wrong way, or
it's not returning what I am hoping for.

Can someone shed some light on this for me?

Thanks.


Dennis Hancy
Eaton Corporation
Cleveland, OH



------------------------------

Date: Mon, 14 Aug 2006 16:04:13 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: current directory name in perl
Message-Id: <Xns981F7AE2F2E23asu1cornelledu@127.0.0.1>

"dennishancy@eaton.com" <dennishancy@eaton.com> wrote in 
news:1155570786.997753.38140@h48g2000cwc.googlegroups.com:

> Is there a function in perl that will tell me the directory name of the
> currently running script?
> 
> In other words, I want to run the script c:\someDirName\scriptName.exe,
> and I want to find a function that will return "c:\someDirName\".

perldoc FindBin

> I found tellDir and seekDir, but I am either using it the wrong way, or
> it's not returning what I am hoping for.

I am not sure what you are referring to here. There are no such Perl 
functions. On the other hand,

perldoc -f telldir

perldoc -f seekdir

These functions are used when iterating through the contents of a 
directory via a handle returned from 

perldoc -f readdir

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://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html



------------------------------

Date: 14 Aug 2006 10:59:49 -0700
From: "dennishancy@eaton.com" <dennishancy@eaton.com>
Subject: Re: current directory name in perl
Message-Id: <1155578389.704368.183890@i3g2000cwc.googlegroups.com>

Ok, well I am getting closer.

I have the value "c:\someDirName\scriptName.pl" stored in a variable.
Now the rest should be easy (if I only knew my regular expression
syntax).

The ultimate goal is to store "c:\someDirName".  So somehow I have to
chop off everything after the last \ character.

Can someone help me with the syntax?  Thanks.


Dennis



dennishancy@eaton.com wrote:
> Is there a function in perl that will tell me the directory name of the
> currently running script?
>
> In other words, I want to run the script c:\someDirName\scriptName.exe,
> and I want to find a function that will return "c:\someDirName\".
>
> I found tellDir and seekDir, but I am either using it the wrong way, or
> it's not returning what I am hoping for.
>
> Can someone shed some light on this for me?
> 
> Thanks.
> 
> 
> Dennis Hancy
> Eaton Corporation
> Cleveland, OH



------------------------------

Date: Mon, 14 Aug 2006 18:26:24 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: current directory name in perl
Message-Id: <Xns981F92FD9FDEAasu1cornelledu@127.0.0.1>

"dennishancy@eaton.com" <dennishancy@eaton.com> wrote in 
news:1155578389.704368.183890@i3g2000cwc.googlegroups.com:

[ It is always fun to find out I might have been killfiled by a 
  top-poster who is documentationally challenged. 

  If you do see this message, please stop top-posting.
  Please at least skim through some documentation. On Windows, a link to
  the HTML formatted docs is installed in the program group. It is 
  really not that hard to find.

  Please read the posting guidelines for this group.
]

> dennishancy@eaton.com wrote:
>> Is there a function in perl that will tell me the directory 
>> name of the currently running script?
>>
>> In other words, I want to run the script c:\someDirName
>> \scriptName.exe, and I want to find a function that will return 
>> "c:\someDirName\".

perldoc FindBin

>> it's not returning what I am hoping for.

What does hope have anything to do with anything?

http://groups.google.com/group/comp.lang.perl.misc/msg/e40a13085b736b96


> Ok, well I am getting closer.

You are not.

> I have the value "c:\someDirName\scriptName.pl" stored in a variable.
> Now the rest should be easy (if I only knew my regular expression
> syntax).

I don't see why regular expressions are needed.
 
> The ultimate goal is to store "c:\someDirName".  So somehow I have to
> chop off everything after the last \ character.

I recommend you use FindBin. This is the purpose for which it was 
written.

> Can someone help me with the syntax?  Thanks.

There are better ways of dealing with paths.

perldoc File::Basename


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://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html



------------------------------

Date: Mon, 14 Aug 2006 11:26:34 -0700
From: "J. Fowler" <user@example.invalid>
Subject: Re: current directory name in perl
Message-Id: <1i3Eg.374$B4.857521@nntp.csufresno.edu>

dennishancy@eaton.com wrote:
> Ok, well I am getting closer.
> 
> I have the value "c:\someDirName\scriptName.pl" stored in a variable.
> Now the rest should be easy (if I only knew my regular expression
> syntax).

getcwd => perldoc Cwd


------------------------------

Date: Mon, 14 Aug 2006 20:17:08 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: current directory name in perl
Message-Id: <ebqlvr.1bs.1@news.isolution.nl>

dennishancy@eaton.com schreef:

> Ok, well I am getting closer.
>
> I have the value "c:\someDirName\scriptName.pl" stored in a variable.
> Now the rest should be easy (if I only knew my regular expression
> syntax).
>
> The ultimate goal is to store "c:\someDirName".  So somehow I have to
> chop off everything after the last \ character.
>
> Can someone help me with the syntax?  Thanks.

You need to read the Posting Guidelines of this group.

-- 
Affijn, Ruud

"Gewoon is een tijger."




------------------------------

Date: Mon, 14 Aug 2006 19:28:55 GMT
From: axel@white-eagle.invalid.uk
Subject: Re: current directory name in perl
Message-Id: <X94Eg.13753$lv.6060@fed1read12>

J. Fowler <user@example.invalid> wrote:
> dennishancy@eaton.com wrote:
>> Ok, well I am getting closer.

>> I have the value "c:\someDirName\scriptName.pl" stored in a variable.
>> Now the rest should be easy (if I only knew my regular expression
>> syntax).

> getcwd => perldoc Cwd

getcwd deals with the current working directory, not with the location
of a particular script.

Axel


------------------------------

Date: Mon, 14 Aug 2006 11:07:37 -0400
From: Sherm Pendley <sherm@Sherm-Pendleys-Computer.local>
Subject: Re: Failure with perl2exe
Message-Id: <m2hd0fe4p2.fsf@Sherm-Pendleys-Computer.local>

"MoshiachNow" <lev.weissman@creo.com> writes:

> Running perl2exe gives warniing.
> An executable is created,however it closes immediately with some
> warning that I'm not able to grasp ...too fast...
>
> perl2exe nettestTk.pl
>
> Perl2Exe V8.70 Copyright (c) 1997-2005 IndigoSTAR Software
> Registered to Lev Weissman:levcreo:20060214
> Converting 'nettestTk.pl' to nettestTk.exe
> Warning: Can't locate Mac/InternetConfig.pm
>     at D:\Perl\lib\Net\Config.pm line 40
>     @INC = D:\Perl\lib, D:\Perl\site\lib,
>
> tried installing Mac::InternetConfig.pm with CPAN and ppm,got errors:
>
> cp Carbon.pm blib\lib\Mac/Carbon.pm
> cp AppleEvents.pm ..\blib\lib\Mac\AppleEvents.pm

Your script uses Mac::InternetConfig, Mac::Carbon, and Mac::AppleEvents
modules. What do you hope to accomplish by bundling Mac-only modules into
a Windows-only .exe file?

sherm--

-- 
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net


------------------------------

Date: Mon, 14 Aug 2006 10:55:24 -0400
From: Mark Seger <Mark.Seger@hp.com>
To:  xhoster@gmail.com
Subject: Re: is it possible to efficiently read a large file?
Message-Id: <44E08EDC.6020202@hp.com>


> OK, I used dt to make a 4G file (I have 2 G ram) and then used it again to
> read it like above, it took 1:24 to read 4 Gigs.  (I straced it, and it
> seemed to use only ordinary read commands, same as Perl does.)
> 
> I ran your Perl sysread code, it took 84 seconds, or 1:24, to read the same
> 4G file.
> 
> This is perl, v5.8.8 built for i686-linux-thread-multi

bingo and thank you!  I was using perl 5.8.0 (I know, shame on me) and 
foolishly thought something as basic as the interface between perl and 
system calls was very efficient.  While I'm sure it is, apparantly 
there's enough of a difference between perl versions to matter.  Then 
again, this 'test' system was also RedHat 9 - I know, also ancient.

my latest tests were on 5.8.5 on a dual-socket/dual-core opteron running 
RHEL4/Update4.

btw - I hope like dt...  8-)

-mark


------------------------------

Date: Mon, 14 Aug 2006 11:05:23 -0400
From: Mark Seger <Mark.Seger@hp.com>
To: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: is it possible to efficiently read a large file?
Message-Id: <44E09133.9090809@hp.com>


> sysread effectively 'takes the address' of the scalar you pass in: that
> is, it writes directly into the scalar as given, and only allocates
> memory if it isn't long enough.
great - that's what I was hoping it would do.  As you may have seen from 
my response to Xho, it now appears my problems were in an older version 
of perl!
>>Here's exactly what I'm doing, noting that I'm counting the bytes read 
>>just to make sure I'm reading no more than I should be.  Assuming I 
>>understand what you were saying, I believe I am preallocating the buffer.
>>
>>#!/usr/bin/perl -w
> 
> 
> Instread of -w you want
> 
>     use warnings;
> 
> Also you want
> 
>     use strict;
> 
> and you need to declare your variables with my.
re: -w, I guess I still don't get it vs 'use warnings'
re: strict, you are right and I am lazy, but will try harder...  8-)
>>$reclen=1024*128;
> 
> 
> This is still a very small record size. The overhead of Perl ops is much
> higher than C ops, so each spin round the loop will cost you much more
> in Perl than in C. This makes it more important to minimize the number
> of times you need to loop by reading as much as you reasonably can at a
> time.
I'm not sure I buy that.  The limiting factor here is the disk speed. 
When you write a bunch of 128KB blocks, they first get written to the 
buffer cache and then the i/o scheduler merges them into bigger requests 
(see the merges stat for I/O) so it really doesn't make all that much of 
a difference.  On a 3GHz processor we're not talking a lot of extra time.
>>$buffer=' 'x$reclen;
>>$filename='/mnt/scratch/test';
>>open FILE, "<$filename" or die;
> 
> 
> Use lexical filehandles.
> Use 3-arg open.
> Give a meaningful error message, even for tiny programs.
> 
>     open my $FILE, '<', $filename or die "can't read '$filename': $!";

I'd be curious to know what the benefit is of a 3-arg open - in fact I 
didn't even realize you could do this.
re: error messages - I agree completely with you and virtually ALWAYS 
provide something more meaningful.  In this quick throwaway, I was again 
being lazy.
>>$total=0;
>>$start=time;
> 
> 
> Note that it is often easier to use the Benchmark module for timing
> things.

This is true, but working with performance numbers all the time, I fell 
a lot more comfortable looking at disk stats vs times.  For example, I 
ran my tests on my opteron which has 8GB of ram using an 8GB file and 
found inconsistent disk numbers.  That led me to the belief that the 
aging algorithm for the buffer cache is not truly oldest first.  It 
wasn't until I did a umount/mount that my numbers were what they should 
have been.  I don't believe I could have found that from 'benchmark'
>>while ($bytes=sysread(FILE, $buffer, $reclen))
> 
> 
> This will overwrite the contents of $buffer, starting from the beginning
> each time. You want something more like
> 
>     while ($bytes = sysread($FILE, $buffer, $reclen, $total)) {
> 
> , although you want to bear in mind what I said above about reading as
> much as you can at a time.
super!  and thanks for the coding tips...  8-)
-mark


------------------------------

Date: Mon, 14 Aug 2006 19:08:55 +0100
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: is it possible to efficiently read a large file?
Message-Id: <nqq6r3-0ht.ln1@osiris.mauzo.dyndns.org>

[could you put a blank line between a quote an your reply? It makes
things much clearer...]

Quoth Mark Seger <Mark.Seger@hp.com>:
> 
> > sysread effectively 'takes the address' of the scalar you pass in: that
> > is, it writes directly into the scalar as given, and only allocates
> > memory if it isn't long enough.
>
> great - that's what I was hoping it would do.  As you may have seen from 
> my response to Xho, it now appears my problems were in an older version 
> of perl!

Ah, right. 5.8.0 is known to be very buggy.

> >>Here's exactly what I'm doing, noting that I'm counting the bytes read 
> >>just to make sure I'm reading no more than I should be.  Assuming I 
> >>understand what you were saying, I believe I am preallocating the buffer.
> >>
> >>#!/usr/bin/perl -w
> > 
> > 
> > Instread of -w you want
> > 
> >     use warnings;
> > 
> > Also you want
> > 
> >     use strict;
> > 
> > and you need to declare your variables with my.
>
> re: -w, I guess I still don't get it vs 'use warnings'

use warnings lets you easily turn on or off warnings for a given block,
and lets you control warnings by category.

> re: strict, you are right and I am lazy, but will try harder...  8-)

:)

> >>$reclen=1024*128;
> > 
> > 
> > This is still a very small record size. The overhead of Perl ops is much
> > higher than C ops, so each spin round the loop will cost you much more
> > in Perl than in C. This makes it more important to minimize the number
> > of times you need to loop by reading as much as you reasonably can at a
> > time.
>
> I'm not sure I buy that.  The limiting factor here is the disk speed. 
> When you write a bunch of 128KB blocks, they first get written to the 
> buffer cache and then the i/o scheduler merges them into bigger requests 
> (see the merges stat for I/O) so it really doesn't make all that much of 
> a difference.  On a 3GHz processor we're not talking a lot of extra time.

We're talking about read, not write. I suspect in 5.8.0 your code ended
up spending most of its time in the perl runloop, rather than waiting on
IO.

> >>$buffer=' 'x$reclen;
> >>$filename='/mnt/scratch/test';
> >>open FILE, "<$filename" or die;
> > 
> > 
> > Use lexical filehandles.
> > Use 3-arg open.
> > Give a meaningful error message, even for tiny programs.
> > 
> >     open my $FILE, '<', $filename or die "can't read '$filename': $!";
> 
> I'd be curious to know what the benefit is of a 3-arg open - in fact I 
> didn't even realize you could do this.

There are two benefits: it cleanly deals with files with any characters
in their names, and it lets you use IO layers (see PerlIO).

Consider what would happen if (for example) $filename began with a '+'.

> > Note that it is often easier to use the Benchmark module for timing
> > things.
> 
> This is true, but working with performance numbers all the time, I fell 
> a lot more comfortable looking at disk stats vs times.

Maybe... I don't know about that. The point is, using Benchmark is
easier and more reliable than just calling time.

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.            benmorrow@tiscali.co.uk


------------------------------

Date: Mon, 14 Aug 2006 11:33:05 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Is there arithmetic sequence represents?
Message-Id: <g69u04f9vta.fsf@CN1374059D0130.kendall.corp.akamai.com>

On 11 Aug 2006, benmorrow@tiscali.co.uk wrote:

> Quoth Ted Zlatanov <tzz@lifelogs.com>:
>> On 10 Aug 2006, anno4000@radom.zrz.tu-berlin.de wrote:
>>
>>> Ted Zlatanov  <tzz@lifelogs.com> wrote in comp.lang.perl.misc:
>>
>>>> my $start = shift @_;
>>>
>>> "shift @_" is the same as just "shift", which is much more common in
>>> this function.
>>
>> I know this.  I prefer to be explicit.  I also say "shift @ARGV" in
>> the main body, so it's clear what I'm shifting.
>
> It is clear what you're shifting: an unqualified 'shift' shifts off the
> current argument list (in all cases). Writing the @_ explicitly simply
> causes someone who knows Perl to have to do a double-take and verify
> that the code is in fact shifting @_.

I also use single-space indents, do I have to change that too?  I
really think you and Anno are nit-picking style here.  Please let me
write out "shift @_".  It amuses me and harms no one.

> putting every parameter on its own line with its own bit of '= shift
> @_;' boilerplate makes it much harder to see what the function is
> actually doing.

Well, I guess we'll have to disagree on this.  Let's drop it, please.

>>>> my @ret;
>>>>
>>>> while ($start <= $end)
>>>> {
>>>> push @ret, $start;
>>>> $start += $increment;
>>>> }
>>>>
>>>> return @ret;
>>>> }
>>>>
>>>> print "$_\n" foreach matlab_list(2, 2, 12);
>>>
>>> There's nothing wrong with your function, but it's awfully roundabout.
>>> Apart from the argument-passing, you failed to follow Tony Curtis'
>>> advice (still preserved near the beginning) to use map for list
>>> generation.  Your loop can be replaced with a little arithmetic
>>> and a map:
>>>
>>> sub matlab_list {
>>> my ( $start, $inc, $end) = @_;
>>> map $start + $inc*$_, 0 .. ($end - $start)/$inc;
>>> }
>>
>> I think my function is more suitable for a beginner example.  The
>> function you show is absolutely terrible for that purpose IMHO.  In
>> terms of efficiency I agree with you, but I wasn't aiming for that.
>
> Efficiency has nothing to do with it: Anno's version is much clearer.

You've got to be kidding.  It mashes map without a clear code block
demarcation, uses a range with a recalculated end point on the fly,
and doesn't use return.  All in a single line.  I'm not criticing
*Anno's code*, just pointing out that for that to be clearer than my
while/push/return code *to a beginner*, you'd have to be on several
medications, none sold over the counter.

> I would perhaps agree that for a beginner who has some experience
> with C-like or Pascal-like languages an explanation of what map does
> in terms of a loop might be helpful, but if we wish to teach people
> to write Perl as opposed to C-as-a-subset-of-Perl then this is a
> very good example of when map makes things substantially
> simpler. (Not that there's anything *wrong* with writing
> C-as-a-subset-of-Perl if that's all someone is prepared or able to
> learn, but I would have thought that in this group we should be
> encouraging people to learn to use Perl properly. Otherwise they'll
> never love it :).)

I think Anno's code is clever, correct, fun, but not something I'd
want to see in a production environment or shown to a beginner.

I think you and many posters here like clever code that accomplishes
several things in one shot.  That's great, but please don't push that
on beginners who don't yet know what an anonymous code block does.
Please don't assume it's "proper" Perl, either.  It's fine Perl, but
as we all know there is no "proper" way to do things in Perl,
TMTOWTDI.

I noticed mine is buggy, I forgot to check that $inc is greater than
zero.  It will loop forever otherwise.  Sorry about that.  Anno's code
will just die if $inc is zero, which is definitely nicer to the user.

Ted


------------------------------

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 9602
***************************************


home help back first fref pref prev next nref lref last post