[17618] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5038 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Dec 5 14:15:41 2000

Date: Tue, 5 Dec 2000 11: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: <976043721-v9-i5038@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 5 Dec 2000     Volume: 9 Number: 5038

Today's topics:
    Re: Sorting the result of a function <jrw32982@my-deja.com>
    Re: Sorting the result of a function <jrw32982@my-deja.com>
    Re: Sorting the result of a function <jeffp@crusoe.net>
    Re: submit a HTML file using a textarea within a form nobull@mail.com
        Triva Game via Perl <lmoran@wtsg.com>
    Re: unsolved: <STDIN> (Anno Siegel)
    Re: unsolved: <STDIN> (Anno Siegel)
    Re: unsolved: <STDIN> <schneider@xtewa.de>
    Re: unsolved: <STDIN> (Tad McClellan)
    Re: unsolved: <STDIN> <schneider@xtewa.de>
    Re: unsolved: <STDIN> <schneider@xtewa.de>
    Re: What if $SIG{__DIE__} is occupied by other module? (Ilya Zakharevich)
    Re: What if $SIG{__DIE__} is occupied by other module? nobull@mail.com
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Tue, 05 Dec 2000 16:33:57 GMT
From: John Wiersba <jrw32982@my-deja.com>
Subject: Re: Sorting the result of a function
Message-Id: <90j5dl$9hv$1@nnrp1.deja.com>

garry@zvolve.com wrote:
> `sort f() ...' looks like `sort SUBNAME LIST' while `sort +f() ...'
> looks like `sort LIST'.

Maybe to the perl parser, but not to a human.  s/sort/foo/g and then
tell me what "foo f()" looks like.

--
John Wiersba


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 05 Dec 2000 16:32:09 GMT
From: John Wiersba <jrw32982@my-deja.com>
Subject: Re: Sorting the result of a function
Message-Id: <90j5aa$9gq$1@nnrp1.deja.com>

garry@zvolve.com wrote:
> But not with the sort() parameter prototype that is described in
> perldoc -f sort:
 ...
>                  @sortedclass = sort byage @class;

But my code doesn't say "sort f @LIST".  It says "sort f(...)".  Is
there not a big visual and cognitive difference?  "f(...)" looks like a
function call.  "f @LIST" looks like a bare word followed by a list and
consequently is much less prone to misinterpretation.

See also my previous post in this thread where the phrase "looks like a
function, therefore it is a function" is bandied about.

> >> See the sort() entry in the perlfunc manual page.
> >
> >I don't see anything in there referring to this bizarre behavior.
>
> See above; it's the first prototype that is listed.

I don't see how a prototype for sort() is supposed to explain that you
cannot pass as an argument to sort() the result of a function-call
written using "normal" function-call syntax.

Bottom line:

I believe I understand what perl is doing.  I believe I understand why
perl is doing it.  But that doesn't make it right.

You're saying, in effect, that:
   foo f(...)
is a call to f() whose list-context result is passed to foo().  Except
if foo == sort, in which case it's a call to sort() passing it a
function name f and a list.

I really find it incredible that a) a language could be designed to work
this way, and b) people would defend it as if it made sense.

(Sorry, Garry, if you're not really defending perl.  But I haven't
heard even a single voice say, "Yea, you're right, it's unbelievably
ugly; but that's the way it is and here's why...".)

--
John Wiersba


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 5 Dec 2000 13:54:29 -0500
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: Sorting the result of a function
Message-Id: <Pine.GSO.4.21.0012051347280.5826-100000@crusoe.crusoe.net>

[posted & mailed]

On Dec 5, John Wiersba said:

>> `sort f() ...' looks like `sort SUBNAME LIST' while `sort +f() ...'
>> looks like `sort LIST'.
>
>Maybe to the perl parser, but not to a human.  s/sort/foo/g and then
>tell me what "foo f()" looks like.

foo is not sort.  There are things in Perl that have specific rules and
contexts applied to them.

  sort this @that;
  sort this (@that);
  sort this(@that);

all do the same thing -- that is, use 'this' as the name of a comparison
function, and @that as the list of items to sort.

If you place a unary + in front of this(@that), perl's lexer knows not to
interpret 'this' as the SUBNAME part.

It's a matter of context, and understanding that you can't get what you
want all the time.

-- 
Jeff "japhy" Pinyan     japhy@pobox.com    http://www.pobox.com/~japhy/
CPAN - #1 Perl Resource  (my id:  PINYAN)       http://search.cpan.org/
PerlMonks - An Online Perl Community          http://www.perlmonks.com/
The Perl Archive - Articles, Forums, etc.   http://www.perlarchive.com/





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

Date: 05 Dec 2000 17:52:23 +0000
From: nobull@mail.com
Subject: Re: submit a HTML file using a textarea within a form
Message-Id: <u9zoia7o2w.fsf@wcl-l.bham.ac.uk>

Karsten Hachmeister <Karsten@Hachmeister-Online.de> writes:

> I have a problem...

Please post a minimal (strict, warning free) script that illustrates
your problem.  Anything else is a waste of your time and ours.

The following script does not reproduce your problem here, does it
reproduce your problem there?

#!/usr/bin/perl -w
use strict;
use CGI ':standard';

print header,start_html,start_form,
	textarea('foo'),submit,end_form,end_html;
__END__

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Tue, 05 Dec 2000 13:14:25 -0500
From: Lou Moran <lmoran@wtsg.com>
Subject: Triva Game via Perl
Message-Id: <0k0q2t8e99j07vvqbkqoql8i0psanf6fdc@4ax.com>

---I have this idea I will write a trivia game with perl.

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

print "Welcome to the Trivia Game\n\n";
print "Answer questions with one uppercase number, \n\n";

print "What is your favorite color?\n\n";

print "10. Yellow, 11. Blue, 12. Green, 13. I don't know\n\n";

my $answer=<STDIN>;
chomp $answer;
my $canswer=10;

unless ($answer eq "10") {
print  "$answer is wrong, please try again.\n";
}
if ($answer eq "10"){
print "Good work! \n\n";
}

***yes, there would be a die statement if they didn't use a number to
answer... yes there would be a while statement so the program didn;t
just throw them out when they answer...

---The perl question is I would want to maintain the question and
answer database somewhere else to add and subtract questions.  I know
how to read a list (ala Secret Word List in LP on Win32 Syetems) but I
don't know how to get list info to display <print> (or better yet make
it "become" HTML code, in fact I have no idea how to make anything
HTML in perl.)  I have looked in perldoc but like find in *nix I
haven't really mastered that (and I lent someone who can actually do
useful things with perl my LPOW32S book.)

any help would be well, helpful.



mmmmm... pointy

lmoran@wtsg.com


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

Date: 5 Dec 2000 14:26:14 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: unsolved: <STDIN>
Message-Id: <90itu6$1u5$1@lublin.zrz.tu-berlin.de>

SimBean  <schneider@xtewa.de> wrote in comp.lang.perl.misc:

>Am I just to stupid?
>Please tell me where to find that faq (it obviously isn't on perl.com)
>and I won't bother you anymore ...

What about http://www.perl.com/pub/v/faqs?  The link is right on the
top page.

Anno


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

Date: 5 Dec 2000 14:47:57 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: unsolved: <STDIN>
Message-Id: <90iv6t$21e$1@lublin.zrz.tu-berlin.de>

SimBean  <schneider@xtewa.de> wrote in comp.lang.perl.misc:

>Hi,
>
>hmh, I think it doesn't work the way it should - but why?
>
>
>That's what I am doing:
>
>
>#!perl -w
>use strict;
>
>my $input;
>open( INPUT, "<&STDIN" );
>select( INPUT ); $| = 1;

$| only affects output.  It is useless here.

>while(1)
>{
>  print STDOUT $input . "\n" if( sysread ( INPUT, $input, 1 ) );
>}
>close ( INPUT );
>
>and it still reads the input only after hitting enter...

The Term::ReadKey module from CPAN does what you want.  Also, find
"How do I check whether input is ready on the keyboard?" in perlfaq8.
Even though it doesn't seem to apply directly, it shows you how
to get ReadKey in the right mode.

Anno


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

Date: Tue, 05 Dec 2000 14:59:16 GMT
From: SimBean <schneider@xtewa.de>
Subject: Re: unsolved: <STDIN>
Message-Id: <90ivs0$4oa$1@nnrp1.deja.com>


> What about http://www.perl.com/pub/v/faqs?  The link is right on the
> top page.
I didn't know he was talking about that, because I searched perl.com
for the subject and it didn't show me any link to that faq. And I could
have bet I had searched the whole faq for that subject before I posted
the message ...

Anyway: it doesn't work the way they describe it! :)

Is it maybe because I am using WinNT??


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 5 Dec 2000 09:54:58 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: unsolved: <STDIN>
Message-Id: <slrn92q0e2.ni3.tadmc@magna.metronet.com>

SimBean <schneider@xtewa.de> wrote:
>
>> >I would just check if there _is_ input
>> Perl FAQ, part 8:
>>    "How do I check whether input is ready on the keyboard?"
>> You inch ever closer to earning yourself a killfile entry.
>> Better stop doing that quick before it gets to be too late...
>Ok, even after _knowing_ what to look for, I didn't find it!
>Am I just to stupid?


What about those steps you claim to follow?

A Deja power search for "FAQ" in c.l.p.misc finds:

   Subject: [Perl] How to find the Perl FAQ

Posted here 3 days ago (December 2).


>Please tell me where to find that faq (it obviously isn't on perl.com)
>and I won't bother you anymore ...


You won't be bothering me anymore for a few months regardless
of whether you find them or not  :-(


>btw: I hope that there are more tolerant people out there that know
>perl!!!


For your sake, I hope so too, since I won't be seeing your posts
for a while.

Expecting that folks will just let you take cuts in line seems
an unreasonable expectation though...


-----------------------------------
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.
-----------------------------------


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


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

Date: Tue, 05 Dec 2000 15:49:36 GMT
From: SimBean <schneider@xtewa.de>
Subject: Re: unsolved: <STDIN>
Message-Id: <90j2qd$7c5$1@nnrp1.deja.com>


> >Hi,
> >
> >hmh, I think it doesn't work the way it should - but why?
> >
> >
> >That's what I am doing:
> >
> >
> >#!perl -w
> >use strict;
> >
> >my $input;
> >open( INPUT, "<&STDIN" );
> >select( INPUT ); $| = 1;
> $| only affects output.  It is useless here.
That's what they said in the faq! I thought it would trigger
flushing ... ?!


> The Term::ReadKey module from CPAN does what you want.  Also, find
> "How do I check whether input is ready on the keyboard?" in perlfaq8.
> Even though it doesn't seem to apply directly, it shows you how
> to get ReadKey in the right mode.
Yes, I tried that, too. It seems like this module isn't installed on my
pc. If there is no other way to solve the problem, I am going to get it.

btw: will it work on a WinNT-pc??

Ciao,
SimBean.


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 05 Dec 2000 16:56:00 GMT
From: SimBean <schneider@xtewa.de>
Subject: Re: unsolved: <STDIN>
Message-Id: <90j6ms$au4$1@nnrp1.deja.com>


> For your sake, I hope so too, since I won't be seeing your posts
> for a while.
>
> Expecting that folks will just let you take cuts in line seems
> an unreasonable expectation though...
Please see my email about this ...


Ciao,
SimBean.


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 5 Dec 2000 18:37:28 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: What if $SIG{__DIE__} is occupied by other module?
Message-Id: <90jcl8$ku5$1@charm.magnus.acs.ohio-state.edu>

[A complimentary Cc of this posting was sent to Bart Lateur 
<bart.lateur@skynet.be>],
who wrote in article <mplp2ts0j4p0k1qqirf1jf0ube36v9m47l@4ax.com>:
> >So do not set $SIG{__DIE__}, use eval {} and all will be well.
> 
> And what happened to TMTOWTDI?

TMTOWT understand TMTOWTDI.

> $SIG{__DIE__}, IMO, is a hook which serves to customize the error
> message, or at leats, the printout of the error message. eval BLOCK
> serves to *prevent* an error message, and fatality.

Nope.  eval BLOCK is used *to intercept* the error condition, not to
prevent it.  Having intercepted it, you have a complete right to
inspect it, customize it, and rethrow the error.

So there is indeed a lot of similarity between the functionality of
$SIG{__DIE__} and eval BLOCK.  The largest difference is that
$SIG{__DIE__} is called first, and eval BLOCK are called after this
(inside out, if rethrowing).

This makes $SIG{__DIE__} more suitable only in the situations when you
want to see the original error text, *and* want to see errors which
were catched and not rethrown.

> So why is a callback function to customize the error output
> even called, when error messages  aren't supposed to be printed? This is
> nonsense.

See above.

> BS. Now, there are at least two modules available from CPAN where
> there's a fatal error if you had set $SIG{__DIE__}. So you claim this is
> a bug in these modules? I think not.

Oh yes, I see.  A misbehaviour of a module cannot be a module's fault
as far as it is on CPAN?

Ilya


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

Date: 05 Dec 2000 18:30:16 +0000
From: nobull@mail.com
Subject: Re: What if $SIG{__DIE__} is occupied by other module?
Message-Id: <u9vgsy7mbr.fsf@wcl-l.bham.ac.uk>

Bart Lateur <bart.lateur@skynet.be> writes:

> nobull@mail.com wrote:
> 
> >Bart Lateur <bart.lateur@skynet.be> writes:
> >
> >> >eval{} is the proper (stackable) way to catch exceptions.
> >> 
> >> No: eval() is the CAUSE of the problem.
> >
> >No - mixing the two mechanisms of trapping __DIE__ exceptions is the
> >cause of the problem.  If you had used only eval{} you'd not have a
> >problem.
> 
> >So do not set $SIG{__DIE__}, use eval {} and all will be well.
> 
> And what happened to TMTOWTDI?

TMTOWTDI with IO too, but if you mix buffered and unbuffered IO
expect problems unless you take precautions.

> $SIG{__DIE__}, IMO, is a hook which serves to customize the error
> message, or at leats, the printout of the error message. eval BLOCK
> serves to *prevent* an error message, and fatality. 

There's no reason not to wrap your whole program in an eval{}.  This
is the C++ way.

> So why is a callback function to customize the error output even
> called, when error messages aren't supposed to be printed? This is
> nonsense.

IMO, for most purposes $SIG{__DIE__} is a relic, superceeded by eval.
I'd only resort to it when the higher level mechanism could not be
used - such as for trapping errors during the initial compliation
phase.

> $SIG{__DIE__}, as a hook, is layered on top op the standard behaviour.
> Currently, eval BLOCK is layered *between* $the default behaviour, and
> the $SIG{__DIE__} handler. It should really be, IMO, layered *on top* of
> it, instead.

I don't think I understand your use of "on top".  I'm not sure if I
would agree with you if I understood you.
 
> In a way, it'd even make sense if eval made use of the $SIG{__DIE__}
> hook mechanism.

I'm now undecided if I'd like to see eval localize $SIG{__DIE__}.
When this thread started out I was definitely opposed to this because
I was affraid it was backward incompatible change but now I've found
the manual warns that this backward incompatible change I see less
reason why it should't be done.

It would not make sense if eval made use of the $SIG{__DIE__} hook
mechanism because then setting a $SIG{__DIE__} handler inside an
eval{} block would then have the same counterintuative behaviour.
We'd just be trading one counterintuative behaviour for another.

> >It is all well documented, as is the $^S work-round so I see no urgent
> >need to fix it even if the docs warn that one day it may be fixed.
> 
> BS. Now, there are at least two modules available from CPAN where
> there's a fatal error if you had set $SIG{__DIE__}. So you claim this is
> a bug in these modules? I think not.

No, the bug is in your __DIE__ handler.  The docs on writing die
handlers tell you of the need to check $^S and you didn't do it.

> Isn't that just a bit too low level?

$SIG{__DIE__} _is_ a low-level constuct.  Your __DIE__ handler may get
executed while the parser in an inconsistant state.  If that isn't low
level I don't know what is.  If you don't want to get into low level
stuff then you should be using eval.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

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


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