[22402] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4623 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 25 18:05:42 2003

Date: Tue, 25 Feb 2003 15:05:06 -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, 25 Feb 2003     Volume: 10 Number: 4623

Today's topics:
    Re: editting photos on the fly <abigail@abigail.nl>
        Getting answers with perldocs <ellem52@mail.com>
    Re: Getting answers with perldocs <penny1482@attbi.com>
    Re: Getting answers with perldocs <usenet@dwall.fastmail.fm>
    Re: Getting answers with perldocs <usenet@dwall.fastmail.fm>
    Re: Just wanted to share this technique (and hear some  (Anno Siegel)
    Re: locate 1, 1 wont work properly, perhaps it's only m (Anno Siegel)
    Re: locate 1, 1 wont work properly, perhaps it's only m <mgjv@tradingpost.com.au>
    Re: locate 1, 1 wont work properly, perhaps it's only m (Anno Siegel)
    Re: locate 1, 1 wont work properly, perhaps it's only m (Jay Tilton)
    Re: Long strings're causing problems <noreply@gunnar.cc>
    Re: Long strings're causing problems <bkennedy@hmsonline.com>
    Re: Long strings're causing problems <noreply@gunnar.cc>
        Passing 2D arrays? <mail@annuna.com>
    Re: Passing 2D arrays? <trh411@earthlink.net>
    Re: Passing 2D arrays? <shondell@cis.ohio-state.edu>
    Re: Passing 2D arrays? <mjcarman@mchsi.com>
        require subs and global parameters (kydongau)
    Re: setting smalldatetime column to NULL <usenet@dwall.fastmail.fm>
    Re: Splice problem <tore@aursand.no>
    Re: Splice problem <usenet@dwall.fastmail.fm>
    Re: translate ( tr ) question (Tad McClellan)
    Re: translate ( tr ) question <mgjv@tradingpost.com.au>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 25 Feb 2003 21:26:12 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: editting photos on the fly
Message-Id: <slrnb5nnrk.bnn.abigail@alexandra.abigail.nl>

Steve (sdyck@engr.uvic.ca.spam) wrote on MMMCDLXIV September MCMXCIII in
<URL:news:3E5A5127.29BC40E2@engr.uvic.ca.spam>:
;;  I am probably months behind on this one, but I recently was sent an
;;  e-mail with a link where I enter my name and it shows up on a picture. 
;;  I tried completely random names to be sure it wasn't just a database of
;;  millions of pictures.
;;  
;;  So my question is, how do they do this?

What makes you think this group is the appropriate place to ask?
Why don't you just mail the people from www.kicken.com?

;;  the link was www.kicken.com.  I'll warn you though.  Your name will
;;  appear on a sign that says "I love <your name>" which is in front of a
;;  topless girl.  be sure you are of legal age before going to the site.


As opposed to having an 'illegal age'?


Abigail
-- 
# Count the number of lines; code doesn't match \w. Linux specific.
()=<>;$!=$=;($:,$,,$;,$")=$!=~/.(.)..(.)(.)..(.)/;
$;++;$*++;$;++;$*++;$;++;`$:$,$;$" $. >&$*`; 


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

Date: Tue, 25 Feb 2003 14:34:59 -0500
From: LM <ellem52@mail.com>
Subject: Getting answers with perldocs
Message-Id: <krfn5voir0kvehtprnh8f6pd4ls27met5n@4ax.com>

Let's pretend I have no Perl Books, and no internet connection; I have
to find all of my info with Perldocs.  Certainly Perldocs is "deep"
enough for all my questions.

How would I find answers to these questions....

Removing Spaces In Files Names
Renaming All Files With An Appended Number
Merging File Contents
Making  List, Checking It Twice
Making text HTML, XML

I need perldoc tips that perldoc perldoc isn't helping me with.  I get
answers sometimes but more often than not I either get "junk: (I
know... JIJO) or way too many answers.

Anyway I don't need Perl answers to those questions just hints on how
to ask them.


--
There's more than one way to do it, but only some of them work


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

Date: Tue, 25 Feb 2003 21:35:17 GMT
From: "Dick Penny" <penny1482@attbi.com>
Subject: Re: Getting answers with perldocs
Message-Id: <pkR6a.263840$vm2.202372@rwcrnsc54>


> How would I find answers to these questions....
>
> Removing Spaces In Files Names
> Renaming All Files With An Appended Number
> Merging File Contents
> Making  List, Checking It Twice
> Making text HTML, XML
>
> I need perldoc tips that perldoc perldoc isn't helping me with.  I get
> answers sometimes but more often than not I either get "junk: (I
> know... JIJO) or way too many answers.
>
> Anyway I don't need Perl answers to those questions just hints on how
> to ask them.
I'm no guru as many herein are, and I too often have similar questions.
I've settled on google because I know of  NO OTHER way to search on key
words, at least in Windoze world. IMHO Perldocs are next to useless.
Dick Penny




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

Date: Tue, 25 Feb 2003 21:51:28 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: Getting answers with perldocs
Message-Id: <Xns932DAB7C5D553dkwwashere@216.168.3.30>

LM <ellem52@mail.com> wrote on 25 Feb 2003:

> Let's pretend I have no Perl Books, and no internet connection; I
> have to find all of my info with Perldocs.  Certainly Perldocs is
> "deep" enough for all my questions.
[snip]
> 
> Anyway I don't need Perl answers to those questions just hints on
> how to ask them.

You could start with 

    perldoc perltoc

That will at least give you an overview and perhaps an idea of where 
to look.  You could use grep to search through all the PODs (or HTML, 
depending on your Perl installation).  If you're on Windows, the 
built-in file search off the Start menu can helpful.

It's also useful just to browse through the docs.  You don't have to 
read everything (probably don't have time for that), but at least get 
familiar with what information is where, so that when you need it you 
know where to look for it.  That's another reason why I recommended 
perltoc.

Lurking here is good, too.  I've seen plenty of questions answered 
that I had no use for at the time, but later when I needed to do 
something similar, I already had an idea how to go about it.

It also doesn't hurt to get familiar with the standard modules 
bundled with Perl.  I can't say I know them all intimately (does 
anyone?), but I'm reasonably familiar with what kinds of things they 
do, so I look to them first when I need something I figure there's 
already a module for.  And there's always CPAN, too.

-- 
David K. Wall - usenet@dwall.fastmail.fm
"Oook."


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

Date: Tue, 25 Feb 2003 22:53:17 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: Getting answers with perldocs
Message-Id: <Xns932DB5F7AFA78dkwwashere@216.168.3.30>

Dick Penny <penny1482@attbi.com> wrote on 25 Feb 2003:

> I'm no guru as many herein are, and I too often have similar
> questions. I've settled on google because I know of  NO OTHER way
> to search on key words, at least in Windoze world. IMHO Perldocs
> are next to useless. Dick Penny

I'm definitely not a 'guru' either.  Still, I generally find what I 
need, and I have to use win2000 at work.  But you could use 
perldoc.com.  Or the search function off the Start menu.

Another solution that just occurred to me is to run your own web server 
locally, install some kind of search engine for it to index the Perl 
HTML docs, and then use that to search. TMTOWTDI. :-)

Tom Christiansen wrote a perlman utility that I haven't heard much 
about recently.  As I recall, he didn't like the perldoc program 
either.  I thought there were plans to include perlman in 5.6, but 
we're at 5.8 now and I still don't see it.  I wonder what happened to 
it?

-- 
David K. Wall - usenet@dwall.fastmail.fm
"Oook."


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

Date: 25 Feb 2003 21:42:23 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Just wanted to share this technique (and hear some opinions about    it)
Message-Id: <b3gnvv$e3r$1@mamenchi.zrz.TU-Berlin.DE>

Matija Papec  <mpapec@yahoo.com> wrote in comp.lang.perl.misc:
> X-Ftn-To: Tassilo v. Parseval 

[...]

> >    FUNCTION, SOMETHING;
> >
> >FUNCTION is assumed to either have no argument or some implicit default
> >and SOMETHING is executed afterwards. 
> 
> Ok, so perl will not print anything after comma until we explicitly put
> first argument; and after first argument all statements separated by , are
> considered arguments?

If you replace "statement" with "expression" you are correct.  Consider
that, by the same token, an expression that is not followed by a "," ends
the variable list.

An expression is a statement that has a value.  Other statements, like
"if"s and loops don't make sense where an expression is expected because
they don't return values.  Perl syntax usually disallows this mixup
in the first place.

Anno


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

Date: 25 Feb 2003 21:07:42 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: locate 1, 1 wont work properly, perhaps it's only meant for linux
Message-Id: <b3gluu$cfs$1@mamenchi.zrz.TU-Berlin.DE>

<tyrannous@o-space.com> wrote in comp.lang.perl.misc:

> it doesn't locate the cursor to 1, 1 that is what happens.

No, Prince Entitled, not this way.  So long.

[TOFU snipped]

Anno


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

Date: Tue, 25 Feb 2003 21:31:34 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: locate 1, 1 wont work properly, perhaps it's only meant for linux
Message-Id: <slrnb5no5m.ufd.mgjv@verbruggen.comdyn.com.au>

On 25 Feb 2003 15:00:34 GMT,
	Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> Please don't top-post.  I'm asking you the second time.  If you don't
> know what it is, google for it.
> 
> <tyrannous@o-space.com> wrote in comp.lang.perl.misc:

Don't bother, Anno. This guy has been asked many times before to not
top-post. He's doing it deliberately (or he's really, really stupid)

Martien
-- 
                        | 
Martien Verbruggen      | That's not a lie, it's a terminological
Trading Post Australia  | inexactitude.
                        | 


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

Date: 25 Feb 2003 21:46:42 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: locate 1, 1 wont work properly, perhaps it's only meant for linux
Message-Id: <b3go82$e3r$2@mamenchi.zrz.TU-Berlin.DE>

Martien Verbruggen  <mgjv@tradingpost.com.au> wrote in comp.lang.perl.misc:
> On 25 Feb 2003 15:00:34 GMT,
> 	Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> > Please don't top-post.  I'm asking you the second time.  If you don't
> > know what it is, google for it.
> > 
> > <tyrannous@o-space.com> wrote in comp.lang.perl.misc:
> 
> Don't bother, Anno. This guy has been asked many times before to not
> top-post. He's doing it deliberately (or he's really, really stupid)

Yes, I remember him vaguely.  I don't use a killfile, but next time
I'll remember him less vaguely.

Anno


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

Date: Tue, 25 Feb 2003 22:42:36 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: locate 1, 1 wont work properly, perhaps it's only meant for linux
Message-Id: <3e5bf0d1.53508957@news.erols.com>

Stop top-posting.

Read the posting guidelines immediately:
http://mail.augustmail.com/~tadmc/clpmisc.shtml .
Pay close attention to the subsection titled "Use an effective
followup style."

Answer the clue phone already.  It's ringing off the hook.

<tyrannous@o-space.com> wrote:
: <tyrannous@o-space.com> wrote 
: > "Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote 
: > > <tyrannous@o-space.com> wrote
: > > > "Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote
: > > > > <tyrannous@o-space.com> wrote
: > > > > 
: > > > > > locate 1, 1 wont work properly, perhaps it's only meant for linux
: > > > > >
: > > > > > use Term::ASCIIScreen;
: > > > >
: > > > > What is Term::ASCIIScreen?  It isn't on CPAN.
: > > >
: > > > i'm sorry, i meant ANSIScreen
: > > >
: > > > > > system 'cls'; locate 1,1;
: > > > > > print chr(65);
: > >
: > > So what do you expect it to do, and what does it do instead?  All you
: > > say is that "it doesn't work right".
: >
: > i just want to locate the cursor to 1, 1 or something similar
: > could you tell me how to do this?
:
: it doesn't locate the cursor to 1, 1 that is what happens.

Jane!  Stop this crazy thing!

This is exasperating.  Are you being deliberately obtuse?

There are two questions to answer:
1) What is the program not doing that it should do?
2) What is the program doing that it should not do?

"It doesn't locate the cursor to 1, 1" is what does _not_ happen.
That is the answer to question 1.

We still have no idea what the answer to question 2 is.
Is the cursor being located to, say, (2,1)?
Does the program generate any output at all?  What is that output?
Does the program die with an error message?  What is that message?
Segfault?
Printer catching fire?

Do not bother replying if you do not understand question 2, or if you
feel compelled to say "it doesn't work" one more time, or if you have
not read the posting guidelines.



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

Date: Tue, 25 Feb 2003 21:27:15 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Long strings're causing problems
Message-Id: <b3gkl3$1loi03$1@ID-184292.news.dfncis.de>

Ben Kennedy wrote:
> "Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
> news:b3g613$1m5uui$1@ID-184292.news.dfncis.de...
> 
>>Both Helgi and 
>>Tassilo indicated that, if that's the case, the use of CGI.pm would have 
>>made a difference. Now I understand that it wouldn't.
> 
> Keep in mind that the "problem" consists of many pieces - the user's web 
> browser, the web server, and the script.  If the OP's problem was indeed 
> created by the GET URL exceeding the web server's limit, and the OP had been 
> using CGI.pm, his fix would have been to just turn the GET form into a POST 
> form.  In other words, by using CGI.pm, one can refactor the client/server 
> protocol to something more extensible in just a few seconds, and be sure 
> that it's going to work.

You are assuming that a non-CGI.pm parsing routine doesn't check for 
STDIN. That's not necessarily true. But if it is the case here, I'm 
ready to give you right to some extent. :)

>>However, pushing for CGI.pm at the wrong moment won't speed up convincing 
>>me.
> 
> A script that needs to transparently start using POST data instead of GET 
> data is easily one of the best reasons to use CGI.pm!

Well, you make it sound like a big thing. Personally I have learned the 
basics about CGI and HTTP, and I'm using a parse function, which I copy 
when starting to write a new app, and which does just that - i.e. 
provided that that's what I want, which is not always the case...

/ Gunnar

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Tue, 25 Feb 2003 16:37:59 -0500
From: "Ben Kennedy" <bkennedy@hmsonline.com>
Subject: Re: Long strings're causing problems
Message-Id: <Ewidnf-OM6HFf8ajXTWc3Q@giganews.com>


"Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
news:b3gkl3$1loi03$1@ID-184292.news.dfncis.de...

> Well, you make it sound like a big thing. Personally I have learned the
> basics about CGI and HTTP, and I'm using a parse function, which I copy
> when starting to write a new app, and which does just that - i.e.
> provided that that's what I want, which is not always the case...

What happens when you need to move past the basics?  Are you prepared to
handle multiple parameters with the same value?  Are you absolutely sure
your GET and POST handlers do the same thing?  What if after your 10th
script you discover a bug in your routine - are you prepared to go back and
edit the previous 9 scripts?  If you do not buy into the philosophy of
software reuse, that's ok.  If you don't want to "follow the CGI.pm crowd",
that's ok too.  But at least do yourself a favor - try writing your next 3
scripts with CGI.pm.  I doubt you will ever look back to your old code.

--Ben Kennedy





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

Date: Tue, 25 Feb 2003 23:05:33 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Long strings're causing problems
Message-Id: <b3gqdr$1lt86i$1@ID-184292.news.dfncis.de>

Ben Kennedy wrote:
> "Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
> news:b3gkl3$1loi03$1@ID-184292.news.dfncis.de...
> 
>>Well, you make it sound like a big thing. Personally I have learned the
>>basics about CGI and HTTP, and I'm using a parse function, which I copy
>>when starting to write a new app, and which does just that - i.e.
>>provided that that's what I want, which is not always the case...
> 
> Are you prepared to handle multiple parameters with the same value?

Of course. Can't see how that could be a problem.

> Are you absolutely sure your GET and POST handlers do the same thing?

Yes, for the simple reason that it's the same handler.

> What if after your 10th
> script you discover a bug in your routine - are you prepared to go back and
> edit the previous 9 scripts?

Well, it's just a few lines of code. Guess the risk for bugs in the big 
CGI.pm module is bigger than the risk for bugs in those few, well tested 
lines.

> If you do not buy into the philosophy of software reuse, that's ok.

But I do buy the philosophy. However, recently, in another thread in 
this group, I reacted when somebody stated that modules should be used 
"whereever possible". Somebody helped me express my own view by saying 
that modules should be used "wherever feasible".

Btw, I'm a beginner module author. A few weeks ago I uploaded my first 
CPAN module. :)

> If you don't want to "follow the CGI.pm crowd",
> that's ok too.  But at least do yourself a favor - try writing your next 3
> scripts with CGI.pm.

Maybe I'll do that. To be honest, right now I know little about what I'm 
missing by not using it.

> I doubt you will ever look back to your old code.

Time will tell. ;-)

/ Gunnar

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Tue, 25 Feb 2003 15:50:30 -0600
From: Joe Creaney <mail@annuna.com>
Subject: Passing 2D arrays?
Message-Id: <3E5BE526.102@annuna.com>

I am writing a simple role playing game in PERL.  I would like to know 
if I can pass 2 demential array to functions using references.  If it is 
possible how do I do it?



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

Date: Tue, 25 Feb 2003 22:01:14 GMT
From: "Tom Hoffmann" <trh411@earthlink.net>
Subject: Re: Passing 2D arrays?
Message-Id: <pan.2003.02.25.22.02.39.92962@earthlink.net>

On Tue, 25 Feb 2003 15:50:30 +0000, Joe Creaney wrote:

> I am writing a simple role playing game in PERL.  I would like to know
> if I can pass 2 demential array to functions using references.  If it is
> possible how do I do it?

Sure, just pass a reference to the array to the subroutine, and in the
subroutine use:

$array_ref->[i][j] to refernce the elements


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

Date: 25 Feb 2003 17:10:20 -0500
From: Ryan Shondell <shondell@cis.ohio-state.edu>
Subject: Re: Passing 2D arrays?
Message-Id: <xcwisv8vwoj.fsf@psi.cis.ohio-state.edu>

Joe Creaney <mail@annuna.com> writes:

> I am writing a simple role playing game in PERL.  I would like to know
> if I can pass 2 demential array to functions using references.  If it
> is possible how do I do it?

You can pass a reference to an array of array (references) just like
you would pass any scalar value to a sub.

my $x = [
     [ "foo", "bar", "baz" ],
     [ "one", "two", "three" ] ];

some_sub($x);

If you need more info on data structures and references, I would read
up on the appropriate perldoc entries.

perldoc perldata ( if you're not familiar already )
perldoc perlreftut
perldoc perldsc

and go from there.

Ryan
-- 
perl -e '$;=q,BllpZllla_nNanfc]^h_rpF,;@;=split//,
$;;$^R.=--$=*ord for split//,$~;sub _{for(1..4){$=
=shift;$=--if$=!=4;while($=){print chr(ord($;[$%])
+shift);$%++;$=--;}print " ";}}_(split//,$^R);q;;'


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

Date: Tue, 25 Feb 2003 16:06:13 -0600
From: Michael Carman <mjcarman@mchsi.com>
Subject: Re: Passing 2D arrays?
Message-Id: <b3gpcm$i242@onews.collins.rockwell.com>

On 2/25/2003 3:50 PM, Joe Creaney wrote:
> 
> I would like to know if I can pass 2 demential array to functions 
> using references. If it is possible how do I do it?

Perl doesn't (directly) support multi-dimensional arrays, so I'll assume
your talking about a LoL (list of lists).

Yes, you can.

#!/usr/bin/perl -w
use strict;

my @lol = ([1,2,3],[4,5,6],[7,8,9]);

foo(\@lol);

sub foo {
  my $ar = shift;
  print "$ar->[1][1]\n";
}

__END__
5

see 'perldoc perlreftut' and 'perldoc perlref' for more info.

-mjc



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

Date: 25 Feb 2003 14:55:03 -0800
From: kydongau@yahoo.com.au (kydongau)
Subject: require subs and global parameters
Message-Id: <738c2d89.0302251455.67b87d4c@posting.google.com>

Hi,
 
Is it possible to require a perl file that contains sub routines as
such:
 
#main script
 
my ($cmd);
 
while .... {
   if bla {
      require "lib1.pl";
   } elsif blaaa {
      require "lib2.pl";
   }
}
 
where lib1 and lib2.pl contains the same sub NAME but doing different
things and having access to the global variables $cmd from the main
script ??
 
If the if block is inside a while loop, can the sub NAME be replaced?
 
My script failed when it tries to use $cmd.
 
Thanks,
Ky


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

Date: Tue, 25 Feb 2003 21:32:15 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: setting smalldatetime column to NULL
Message-Id: <Xns932DA83A2A09dkwwashere@216.168.3.30>

 <JavaProgrammer@nowhere.com> wrote on 25 Feb 2003:

> A co-worker is trying to get her PERL script to UPDATE a record so
> a (Sybase System 11) smalldatetime column is set to NULL, but not
> having any luck. Apparently a statement like

Um, it's Perl for the language, perl for the interpreter/compiler.  
PERL is something that some book publishers and PHBs call it.

> 
> UPDATE table
> SET smalldatetimeColumn = NULL
> WHERE ...
> 
> doesn't work though it works fine in SQL Advantage. Is there any
> way to get the above statement to work in PERL? 

Are you using DBI?  Take a look at http://dbi.perl.org

(I don't know why they decided light orange/yellow links on a white 
background were a good idea.  Lime green for hovered links?  Eww. But 
that has nothing to do with Perl).

-- 
David K. Wall - usenet@dwall.fastmail.fm
"Oook."


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

Date: Tue, 25 Feb 2003 22:30:46 +0100
From: "Tore Aursand" <tore@aursand.no>
Subject: Re: Splice problem
Message-Id: <pan.2003.02.25.21.00.44.22631@aursand.no>

On Tue, 25 Feb 2003 16:08:51 +0000, David K. Wall wrote:
> But as Uri Guttman said, grep() is easier to read, as long as you 
> grok grep(). :-)
> 
>     @array = grep length >= 5, @array ;
> 
> Should be faster, too, although getting it right is more important 
> than getting it fast.

It's easier to read, that's right, but according to my benchmarks it's
slower using 'grep' in this case.

Hmm.  Is it just me, or am I really right? :)


-- 
Tore Aursand - tore@aursand.no - http://www.aursand.no/



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

Date: Tue, 25 Feb 2003 22:20:37 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: Splice problem
Message-Id: <Xns932DB06D97AA2dkwwashere@216.168.3.30>

Tore Aursand <tore@aursand.no> wrote on 25 Feb 2003:

> On Tue, 25 Feb 2003 16:08:51 +0000, David K. Wall wrote:
>> But as Uri Guttman said, grep() is easier to read, as long as you
>> grok grep(). :-)
>> 
>>     @array = grep length >= 5, @array ;
>> 
>> Should be faster, too, although getting it right is more
>> important than getting it fast.
> 
> It's easier to read, that's right, but according to my benchmarks
> it's slower using 'grep' in this case.
> 
> Hmm.  Is it just me, or am I really right? :)

Below is the benchmark code I tried.  grep() looks roughly twice as 
fast to me.  It's also interesting that using a lexical variable in 
the foreach loop speeds it up.  

<shrug>  Isn't there a saying that premature optimization is the root 
of all bugs? :-)


use strict;
use warnings;
use Benchmark qw/:all/;


my @array = qw/aa llllllll bbb ccccc dddddd ee f k d e y q s f 
ssssssss/;

my $results = timethese( -5, 
  {
      grep_array => 'my @newarray = grep length > 5, @array;',
      foreach_lex => 
          'my @long; 
           foreach my $el (@array) { 
               push @long, $el  if length $el > 5;
           }',
      foreach => 
          'my @long; 
           foreach (@array) { push @long, $_  if length $_ > 5;}'    
  }
);

print "\n\n";

cmpthese $results;


-- 
David K. Wall - usenet@dwall.fastmail.fm
"Oook."


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

Date: Tue, 25 Feb 2003 13:12:53 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: translate ( tr ) question
Message-Id: <slrnb5ng1l.22m.tadmc@magna.augustmail.com>

Matija Papec <mpapec@yahoo.com> wrote:
> tadmc@augustmail.com (Tad McClellan) wrote:
>>> I need to know how to translate letters higher than 
>>> J to a number i.e. a=1..z=27
                  ^^^^
                  ^^^^
>>   s/[J-Z]/a=1..z=27/g;
>             ^^^^^^^^^
> 
> how this interpolates; 


It doesn't.


The OP said "that is a=1..z=27" so it does what he said to do.

(He meant to say "for example" (e.g.) instead of "that is" (i.e.).
 He was careless in his spec, so he got a useless answer.
)


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Tue, 25 Feb 2003 21:28:28 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: translate ( tr ) question
Message-Id: <slrnb5nnvs.ufd.mgjv@verbruggen.comdyn.com.au>

On Mon, 24 Feb 2003 23:48:10 -0600,
	Tad McClellan <tadmc@augustmail.com> wrote:
> Taber <taber@gonetstat.com> wrote:
>> I need to know how to translate letters higher than 
>> J to a number i.e. a=1..z=27
> 
> 
>    s/([j-z])/ ord($1) - ord('a') + 1/ge;

Just an additional note; This only works for ASCII and derived
character sets. Admittedly that's most of the machine out there, but
it isn't a completely general solution.

Martien
-- 
                        | 
Martien Verbruggen      | Begin at the beginning and go on till you
Trading Post Australia  | come to the end; then stop.
                        | 


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

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.  

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


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