Re: RFC 39 (v3) Perl should have a print operator

2000-09-08 Thread Ask Bjoern Hansen

On Wed, 6 Sep 2000, Bart Lateur wrote:

 Those are not the semantics of print.   It returns true (1) if successful, and
 false (undef) otherwise.  You cannot change that.  If I write print "0", it
 bloody well shan't be returning false.
 
 Oh, why not? Does anybody actually *ever* check the return value of
 print? I think it's not as if we'd break a lot of code.

uh, what? you don't do much socket programming now, do you? sockets
breaks all the time. Disks runs out of space while you write to
files. and so on and so on.

 Problem is: if you need defined() to see if the print was succesful, you
 cannot return what was printed as well. It's one thing or the other. So
 you cannot have it both ways.

I really don't understand why you want to have what's printed. If
you need it in a variable, you can just make the variable first and
then print.


 - ask

-- 
ask bjoern hansen - http://www.netcetera.dk/~ask/
more than 70M impressions per day, http://valueclick.com




Re: RFC 39 (v3) Perl should have a print operator

2000-09-08 Thread Bart Lateur

On Fri, 8 Sep 2000 01:18:19 -0700 (PDT), Ask Bjoern Hansen wrote:

I really don't understand why you want to have what's printed.

It is handy, sometimes.

But I do think that the overhead of creating a longish string every time
you print something, which is then simply discarded, is not really
acceptable. I expect a rather significant slowdown. A rough guess: 20%,
which that is the slowdown I onotice if you print with $\ set to "\n"
instead of to nothing. It's just not worth it.

-- 
Bart.



Re: RFC 39 (v3) Perl should have a print operator

2000-09-08 Thread Chaim Frenkel

 "ABH" == Ask Bjoern Hansen [EMAIL PROTECTED] writes:

 Oh, why not? Does anybody actually *ever* check the return value of
 print? I think it's not as if we'd break a lot of code.

ABH uh, what? you don't do much socket programming now, do you? sockets
ABH breaks all the time. Disks runs out of space while you write to
ABH files. and so on and so on.

Could someone enlighten this poor soul and tell me what I _can_ do
with an error return from a print or close?

Reporting it may be useless (disk full).

While I'm asking, what does one do while switching around file descriptors
and an error is returned. Is there anywhere to report it?

chaim
-- 
Chaim FrenkelNonlinear Knowledge, Inc.
[EMAIL PROTECTED]   +1-718-236-0183



Re: RFC 39 (v3) Perl should have a print operator

2000-09-08 Thread Ask Bjoern Hansen

On 8 Sep 2000, Chaim Frenkel wrote:

  Oh, why not? Does anybody actually *ever* check the return value of
  print? I think it's not as if we'd break a lot of code.
 
 ABH uh, what? you don't do much socket programming now, do you? sockets
 ABH breaks all the time. Disks runs out of space while you write to
 ABH files. and so on and so on.
 
 Could someone enlighten this poor soul and tell me what I _can_ do
 with an error return from a print or close?

rollback transactions to the database, flag the thing you tried to
do as something that should be retried, close and reopen the socket
connection and try again, send a mail to the NOC that the world is
on fire, etcetera, etcetera ...

Tim always refers to
http://search.cpan.org/doc/TIMB/DBI_Talk4_2000/sld024.htm
 
 Reporting it may be useless (disk full).

eh? I like to get someone aware of it so the problem can be fixed. I
also like my application to stop doing whatever it tried to do and
if possibly know what it didn't do so it can try it again later.
 

 - ask 

-- 
ask bjoern hansen - http://www.netcetera.dk/~ask/
more than 70M impressions per day, http://valueclick.com




Re: RFC 39 (v3) Perl should have a print operator

2000-09-06 Thread Tom Christiansen

On Tue, 05 Sep 2000 18:37:11 -0600, Tom Christiansen wrote:

Those are not the semantics of print.   It returns true (1) if successfSNIP
false (undef) otherwise.  You cannot change that.  If I write print "0", it
bloody well shan't be returning false.

Oh, why not? Does anybody actually *ever* check the return value of
print? 

Yes.

 I think it's not as if we'd break a lot of code.

Don't worry, Mercutio, 'tis but a small wound.

Problem is: if you need defined() to see if the print was succesful, you

defined() is superstition.  I said true and false.  If I say true,
I don't want you testing against 1.  If I say false, I don't want
you testing definedness.  Most tests like this should be true or
false.  

cannot return what was printed as well. It's one thing or the other. So
you cannot have it both ways.

I don't *WANT* it to return what it alleges to have printed.  That's
stupid, since I can always get that myself.  I don't need it to
tell me this!

--tom



Re: RFC 39 (v3) Perl should have a print operator

2000-09-05 Thread Jon Ericson

Tom Christiansen wrote:
 Perl already *has* a print operator: "print". :-)

I think what I really want is a tee operator.
 
 The problem with what you have there is that it hides the act of
 output within an arbitrarily long circumfix operator whose terminating
 portion is potentially very far away.  What's wrong with putting a
 command name at the start of a command, anyway?  Note that the
 readline operator is not normally subject to this same problem
 as its operand is a handle, not a long string.

I would consider this to be bad style:

  qq{
  ...
  }; # yuck!

This is what I'd consider good style:

  my @output =
 map { $_-[0] }
 sort { $a-[1] cmp $b-[1] }
 map { [$_, expensive_func($_)] } # print original lines
 ;

(Modified from http://www.perlmonks.org/index.pl?node_id=9108)

The main point of this statement is the Schwartzian Transform, but it
also prints the original lines en passant.  

 Also, it makes it icky to quote Perl code in mail messages;
 see above. :-(

Agreed.  Good style would avoid this problem.  The example in the
synopsis of this RFC should be:

  my $output = "Print this line.\n";

Jon
-- 
Knowledge is that which remains when what is
learned is forgotten. - Mr. King



Re: RFC 39 (v3) Perl should have a print operator

2000-09-05 Thread Tom Christiansen

This is what I'd consider good style:

  my @output =
 map { $_-[0] }
 sort { $a-[1] cmp $b-[1] }
 map { [$_, expensive_func($_)] } # print original lines
 ;

(Modified from http://www.perlmonks.org/index.pl?node_id=9108)

The main point of this statement is the Schwartzian Transform, but it
also prints the original lines en passant.  

Again, I can't *ever* remember wanting a function that did this.  Rare things
shouldn't have hard-to-figure-out names.  Why do you want it?  Debugging or
something?  Have you tried tie?

--tom



Re: RFC 39 (v3) Perl should have a print operator

2000-09-05 Thread Nathan Wiger

Jon Ericson wrote:
 
 I would want it to return @items:
 
   @sorted = sort print @items;
 
 I'd prefer a different name (tee?) and keep print as it is.


Pretty much all the stuff being discussed right now can be stuck in a
module:

   package Print::Variations;

   use Exporter;
   @EXPORT = qw(printl println printj);

   sub printl {
   # return list as-is
   print(@_) ? return @_ : return undef;
   }

   sub printj {
   # return joined string
   my $str = join '', @_;
   print(@_) ? return $str : return undef;
   }

   sub println {
   # add a newline and return T/F
   print(@_, "\n");
   }


   #! perl -w
   use Print::Variations;

   # Make Bart and me happy
   $formatted = printj $r-param('name'), " is $age years old.\n";

   # Make Jon happy
   @sorted = sort { $a = $b } printl "@items\n";

   # Make the Pascal lovers happy
   println "Hello, World!";


Is all this stuff cool? Maybe. Does it belong in core? Definitely not.
Is it important enough to warrant special operators? I remain
unconvinced.

Granted, these functions can't handle different filehandles, etc, but if
some of the RFC's get included that attempt to fix this it should be
trivial.

-Nate



Re: RFC 39 (v3) Perl should have a print operator

2000-08-31 Thread Tom Christiansen

Perl supplies an operator for line input - angle brackets.  This is no
analogous operator for output.  I propose "inverse angle brackets":

"Print this line.\n";

Perl already *has* a print operator: "print". :-)

The problem with what you have there is that it hides the act of
output within an arbitrarily long circumfix operator whose terminating
portion is potentially very far away.  What's wrong with putting a
command name at the start of a command, anyway?  Note that the 
readline operator is not normally subject to this same problem 
as its operand is a handle, not a long string.

Also, it makes it icky to quote Perl code in mail messages; 
see above. :-(

--tom