[17744] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5164 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Dec 20 18:15:40 2000

Date: Wed, 20 Dec 2000 15:15:22 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <977354122-v9-i5164@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 20 Dec 2000     Volume: 9 Number: 5164

Today's topics:
    Re: switch/case in Perl? (Tom Christiansen)
    Re: switch/case in Perl? <bart.lateur@skynet.be>
    Re: switch/case in Perl? <cleon42@my-deja.com>
    Re: switch/case in Perl? <cleon42@my-deja.com>
    Re: switch/case in Perl? <jboes@eoexchange.com>
    Re: switch/case in Perl? <anmcguire@my-deja.com>
    Re: switch/case in Perl? <bart.lateur@skynet.be>
    Re: switch/case in Perl? (Tad McClellan)
    Re: testing if $_ is equal to some string? (Jerome O'Neil)
    Re: Unreserved apologies <russ_jones@rac.ray.com>
    Re: Unreserved apologies (Tad McClellan)
    Re: yet another question: is ' more efficient than "? <iltzu@sci.invalid>
    Re: yet another question: is ' more efficient than "? (Jerome O'Neil)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 20 Dec 2000 12:10:28 -0700
From: tchrist@perl.com (Tom Christiansen)
Subject: Re: switch/case in Perl?
Message-Id: <3a410424@cs.colorado.edu>

In article <91qv39$f0j$1@nnrp1.deja.com>,
Adam Levenstein  <cleon42@my-deja.com> wrote:
>Hey all,
>
>Is there a version of C++'s "switch" function in Perl? As in:

What part of the FAQ's answer to this question did you not understand?
What part of the Camel's answer to this question did you not understand?

--tom, who's convinced he should globally killfile my-deja for
       fricking ever.

PS: And from which C++ library does "function" come from, anyway?


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

Date: Wed, 20 Dec 2000 19:24:12 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: switch/case in Perl?
Message-Id: <1j124tc51k8epr19jllkb2ljtvvdfbpapq@4ax.com>

Adam Levenstein wrote:

>Is there a version of C++'s "switch" function in Perl?

No. thank goodnes for that. The "break" syntax must be most stupid rule
in any language I've ever seen.

Oh, and there's an entry in the FAQ.

	perldoc -q switch
-->
	Found in .../perlfaq7.pod
	  How do I create a switch or case statement?

    This is explained in more depth in the the perlsyn manpage. Briefly,
    there's no official case statement, because of the variety of tests
    possible in Perl (numeric comparison, string comparison, glob
    comparison, regex matching, overloaded comparisons, ...). Larry
    couldn't decide how best to do this, so he left it out, even though
    it's been on the wish list since perl1.

I think that abusing regexes for a switch statement is less than ideal,
but it contains a lot of useful info, too.

-- 
	Bart.


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

Date: Wed, 20 Dec 2000 19:41:00 GMT
From: Adam Levenstein <cleon42@my-deja.com>
Subject: Re: switch/case in Perl?
Message-Id: <91r20b$hoc$1@nnrp1.deja.com>

In article <3a410424@cs.colorado.edu>,
  tchrist@perl.com (Tom Christiansen) wrote:
>
> --tom, who's convinced he should globally killfile my-deja for
>        fricking ever.

But gee, then we'd miss your oh-so-polite, well-mannered responses. In
fact, putting in a killfilter would undoubtedly take less time than
making such a polite response every time someone asks a fairly simple
question.

--
-------------------------------------------------
Adam Levenstein
cleon42@my-deja.com

"Extraordinary claims require extraordinary evidence."
				-- Carl Sagan


Sent via Deja.com
http://www.deja.com/


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

Date: Wed, 20 Dec 2000 19:44:47 GMT
From: Adam Levenstein <cleon42@my-deja.com>
Subject: Re: switch/case in Perl?
Message-Id: <91r27e$i1t$1@nnrp1.deja.com>

Thanks Bart...Just trying to keep the code short.

And yeah - I never understood why Richie put the "break" in there.
Seemed unnecessary to me.

Adam

In article <1j124tc51k8epr19jllkb2ljtvvdfbpapq@4ax.com>,
  Bart Lateur <bart.lateur@skynet.be> wrote:
> Adam Levenstein wrote:
>
> >Is there a version of C++'s "switch" function in Perl?
>
> No. thank goodnes for that. The "break" syntax must be most stupid
rule
> in any language I've ever seen.
>
> Oh, and there's an entry in the FAQ.
>
> 	perldoc -q switch
> -->
> 	Found in .../perlfaq7.pod
> 	  How do I create a switch or case statement?
>
>     This is explained in more depth in the the perlsyn manpage.
Briefly,
>     there's no official case statement, because of the variety of
tests
>     possible in Perl (numeric comparison, string comparison, glob
>     comparison, regex matching, overloaded comparisons, ...). Larry
>     couldn't decide how best to do this, so he left it out, even
though
>     it's been on the wish list since perl1.
>
> I think that abusing regexes for a switch statement is less than
ideal,
> but it contains a lot of useful info, too.
>
> --
> 	Bart.
>

--
-------------------------------------------------
Adam Levenstein
cleon42@my-deja.com

"Extraordinary claims require extraordinary evidence."
				-- Carl Sagan


Sent via Deja.com
http://www.deja.com/


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

Date: Wed, 20 Dec 2000 15:22:13 -0500
From: "Jeff Boes" <jboes@eoexchange.com>
Subject: Re: switch/case in Perl?
Message-Id: <3a4116cd$0$35016$44a10c7e@news.net-link.net>

Unless my newsreader has been taken over by the Illuminati, I think "Adam
Levenstein" <cleon42@my-deja.com> babbled:

> Hey all,
> 
> Is there a version of C++'s "switch" function in Perl? As in:
> 
> switch ($x) {
>   case z: ... case a: ...
> }
> 

$ perldoc -q switch

Found in /usr/lib/perl5/5.6.0/pod/perlfaq7.pod
How do I create a switch or case statement?  


-- 
Jeff Boes <jboes@eoexchange.com>          Tel:  (616) 381-9889 x.18
Sr. Software Engineer, EoExchange, Inc.   http://www.eoexchange.com/
Search, Monitor, Notify.                  http://www.eomonitor.com/


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

Date: Wed, 20 Dec 2000 20:53:28 GMT
From: Andrew N McGuire <anmcguire@my-deja.com>
Subject: Re: switch/case in Perl?
Message-Id: <91r685$lq6$1@nnrp1.deja.com>

In article <91r27e$i1t$1@nnrp1.deja.com>,
  Adam Levenstein <cleon42@my-deja.com> wrote:
> Thanks Bart...Just trying to keep the code short.
>
> And yeah - I never understood why Richie put the "break" in there.
> Seemed unnecessary to me.

[ snip ]

  Well, you may want to have a default case.  If you decide
in your switch that a default case is necessary, then you
must use a break in case you have a case where you do not
want to fall through to the default case.

  Of course one could argue that you never need a default
case, and that you could put the same statement at the end
of every case, or on a case by case basis.  But in the case
of a huge switch, that would begin to become less legible
than having a default case.

:-)

  phhheeeeeewwww (hope I go that right)

anm

--
$ENV{PAGER} = 'perl -wpe0';
system perldoc => '-t', '-F', $0;

=head1 Just Another Perl Hacker


Sent via Deja.com
http://www.deja.com/


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

Date: Wed, 20 Dec 2000 21:59:33 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: switch/case in Perl?
Message-Id: <ura24tkgasil7hkvn1l8rg4vpr8i5o3t6l@4ax.com>

Andrew N McGuire wrote:

>> And yeah - I never understood why Richie put the "break" in there.

>  Well, you may want to have a default case.  If you decide
>in your switch that a default case is necessary, then you
>must use a break in case you have a case where you do not
>want to fall through to the default case.
>
>  Of course one could argue that you never need a default
>case

Nope. You should never need to "fall through". That is like an "if"
statement, where you do the "else" part as well.

-- 
	Bart.


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

Date: Wed, 20 Dec 2000 15:17:27 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: switch/case in Perl?
Message-Id: <slrn9424un.3cd.tadmc@magna.metronet.com>

Adam Levenstein <cleon42@my-deja.com> wrote:
>In article <3a410424@cs.colorado.edu>,
>  tchrist@perl.com (Tom Christiansen) wrote:
>>
>> --tom, who's convinced he should globally killfile my-deja for
>>        fricking ever.
>
>But gee, then we'd miss your oh-so-polite, well-mannered responses. 


Not if you could be troubled to check the Perl FAQ before
posting to the Perl newsgroup. It is standard in nearly *all*
newsgroups to check the FAQ before posting.

It is *you* who broke netiquette.

Don't get all fussy when you get taken to task for asking an
easily found FAQ. You are just being paid back in kind.
(Don't be rude in the first place, and you'll get lots
 less rudeness in return.)


Wait your turn in line. Do you really expect that noone will
say anything when you take cuts in front of them? That seems
a wildly unrealistic expectation.


----------------------------
In article <1995Nov9.193745.13694@netlabs.com>, lwall@netlabs.com (Larry
Wall) wrote: ...

<Larry>  [snip]  I view a programming language as a place to be
<Larry>  explored, like Disneyland. You don't need to have a lot of preparation
<Larry>  to explore a theme park.  You do have to go along with the crowd
<Larry>  control measures, though.  In a sense, each ride has its own
<Larry>  prerequisites--if you cut in line, you risk getting tossed out of the
<Larry>  park.
<Larry> 
<Larry>  What we have here in this newsgroup is a failure in crowd control.
<Larry>  Reading the FAQ is like staying in line--it's something you should
<Larry>  learn in kindergarten.  Usenet needs a better kindergarten.
----------------------------


>someone asks a fairly simple
>question.


But you did not ask a fairly simple question.

You asked a Frequently Asked Question.

Not at all the same thing.

And now that you have displayed the attitude that it is OK to
re-ask FAQs, the chances of your getting help with future Perl
problems has been diminished. I hope your venting was worth 
the trade-off you have made.


*plonk*


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


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

Date: Wed, 20 Dec 2000 20:28:30 GMT
From: jerome@activeindexing.com (Jerome O'Neil)
Subject: Re: testing if $_ is equal to some string?
Message-Id: <OD806.1251$lz1.272932@news.uswest.net>

"John Boy Walton" <johngros@Spam.bigpond.net.au> elucidates:
> 
>> if($_ eq "xxx\n"){ # Foo! }

> or if ( /xxx\\n/ )

A regex would match with or without the line feed.

if(/xxx/){ # Still matches.}

And, as a style preference, if I'm using control or metacharacters in a
regex, I like to change the delimiter for clarity.

if(m!xxx\n!){ #  Nice read!  }

YMMV.

The guy also said he didn't want to "substitute,"  which I interpreted as
"didn't want to use a regex."  My interpretation may be wrong.



-- 
If men could learn from history, what lessons it might teach us!  But
passion and party blind our eyes, and the light which experience gives
is a lantern on the stern, which shines only on the waves behind us.
				--Samuel Taylor Coleridge, "Recollections"


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

Date: Wed, 20 Dec 2000 13:46:59 -0600
From: Russ Jones <russ_jones@rac.ray.com>
Subject: Re: Unreserved apologies
Message-Id: <3A410CB3.F5BE5EB0@rac.ray.com>

Tad McClellan wrote:
> 
> His followup promoted him to a "hard plonk" ( -9998 score )
> due to the ad hominem. Hard plonks are one-way. Once you
> earn that level, there is no going back. You're in there for good.
> 


Just curious, how did his apology get through your "hard plonk?"

-- 
Russ Jones - HP OpenView IT/Operatons support
Raytheon Aircraft Company, Wichita KS
russ_jones@rac.ray.com 316-676-0747

Quae narravi, nullo modo negabo. - Catullus


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

Date: Wed, 20 Dec 2000 15:24:51 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Unreserved apologies
Message-Id: <slrn9425cj.3cd.tadmc@magna.metronet.com>

Russ Jones <russ_jones@rac.ray.com> wrote:
>Tad McClellan wrote:
>> 
>> His followup promoted him to a "hard plonk" ( -9998 score )
>> due to the ad hominem. Hard plonks are one-way. Once you
>> earn that level, there is no going back. You're in there for good.
>> 
>
>
>Just curious, how did his apology get through your "hard plonk?"


Because it wasn't the "hardest plonk"  :-)

Score of -9999 is automatically deleted, I can never see those
ones (There are only 3 people at that lauded level).

-9998 just _marks_ it as deleted, at puts it at the very end
of the list of articles.

I very rarely get that far down the marked-as-deleted section.
In fact, I rarely even look at the Subjects for those articles.
I'm shut down for the holidays already, and had more time than
usual today.


[ And I usually comment-out the plonking for the first day or two, 
  to see if they want to try for a "promotion". Seems that more
  than half do end up qualifying. This OP was an exception to
  make that rule :-)
]


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


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

Date: 20 Dec 2000 19:24:55 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: yet another question: is ' more efficient than "?
Message-Id: <977339250.4849@itz.pp.sci.fi>

In article <91qj11$4ep$1@diana.bcn.ttd.net>, tim allen wrote:
>
>timethese(-2, {
>    concat => sub { my $str = ""; $str .= $_ for @a },
>    join   => sub { my $str = ""; $str = join '', @a },
>    empty  => sub { my $str = "" }
>});

What's this?  Definitely not the code you benchmarked below!


>Benchmark: running double, single, each for at least 2 CPU seconds...
>    double:  3 wallclock secs ( 2.20 usr +  0.00 sys =  2.20 CPU) @ 180949.55/s (n=398089)
>    single:  1 wallclock secs ( 2.14 usr +  0.00 sys =  2.14 CPU) @ 226195.79/s (n=484059)
 [snip]
>As I interpret this, double quotes were 20% less efficient for a short
>string, and 1% less efficient for a slightly longer string, and 4% less

Wrong. The correct interpretation is that the results are entirely
within expected variance, and the performances are probably equal.

A properly conducted benchmark support this conclusion:

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

  timethese 1<<(shift || 0),
    { single => q($_ = 'abcdefghijlkmnopqrstuvwxyz'),
      double => q($_ = "abcdefghijlkmnopqrstuvwxyz"),
    };

  __END__

  Benchmark: timing 4194304 iterations of double, single...
      double: 19 wallclock secs (17.51 usr +  0.01 sys = 17.52 CPU)
      single: 19 wallclock secs (17.75 usr +  0.00 sys = 17.75 CPU)

  Benchmark: timing 4194304 iterations of double, single...
      double: 19 wallclock secs (17.54 usr +  0.00 sys = 17.54 CPU)
      single: 19 wallclock secs (17.77 usr +  0.00 sys = 17.77 CPU)

  This is perl, version 5.005_03 built for i386-linux

-- 
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real!  This is a discussion group, not a helpdesk.  You post
 something, we discuss its implications.  If the discussion happens to
 answer a question you've asked, that's incidental." -- nobull in clpm



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

Date: Wed, 20 Dec 2000 20:35:59 GMT
From: jerome@activeindexing.com (Jerome O'Neil)
Subject: Re: yet another question: is ' more efficient than "?
Message-Id: <PK806.1260$lz1.277544@news.uswest.net>

merlyn@stonehenge.com (Randal L. Schwartz) elucidates:

> On the flipside, I double-quote nearly everything that isn't just a
> single word, because during maintenance, I'm almost always adding or
> removing \n and friends, and going to back to fix a string that was
> single-quoted is a pain in the hiney.

Damn three sided coins...

I solve this by not using single and double quotes at all, but alternate
quoting methods.

q{Fee fie foe};

can then become

qq{Fee fie foe};

quite easily.


-- 
If men could learn from history, what lessons it might teach us!  But
passion and party blind our eyes, and the light which experience gives
is a lantern on the stern, which shines only on the waves behind us.
				--Samuel Taylor Coleridge, "Recollections"


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 5164
**************************************


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