[27753] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9137 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Apr 9 18:05:36 2006

Date: Sun, 9 Apr 2006 15:05:03 -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           Sun, 9 Apr 2006     Volume: 10 Number: 9137

Today's topics:
    Re: A problem with precedence <abigail@abigail.nl>
        DOS globbing <rvtol+news@isolution.nl>
    Re: Extract range of lines from a text file <tadmc@augustmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 09 Apr 2006 22:00:56 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: A problem with precedence
Message-Id: <slrne3j10o.31m.abigail@alexandra.abigail.nl>

Lukas Mai (rwxr-xr-x@gmx.de) wrote on MMMMDCIV September MCMXCIII in
<URL:news:e1b1nt$98g$00$1@news.t-online.com>:
<>  Mark Hobley <markhobley@hotpop.deletethisbit.com> schrob:
<>  
<> > I now add brackets to change the precedence:
<> > 
<> > print (4 + 2) * 3; # This unexpectedly gives 6
<>  
<>  Use warnings.

Actually, the fact this gives a warning is a damn good reason to NOT
use warnings. 

Because Perl is more often wrong about this warning than it is right.
If I were to advocate against using Perl, I'd point out the warnings
it gives with 'print', and then rest my case. 

  print(4 + 2) * 3;       # No warning.
  print (4 + 2) * 3;      # Warning.
  print	(4 + 2) * 3;      # No warning (!)
  print  (4 + 2) * 3;     # No warning.

Four mistakes, only one warning.

But it gets better.

  print (4 + 2) * 3;      # Warning.
  printf (4 + 2) * 3;     # Warning.
  sprintf (4 + 2) * 3;    # No warning.
  sort (4 + 2) * 3;       # Warning.
  sin (4 + 2) * 3;        # No warning.

Perl also tries to be smart by looking what's following the parenthesis.
Only to end up looking like an utter fool.

  print (4 + 2) if 0;     # No warning.
  print (4 + 2) while 0;  # No warning.
  print (4 + 2) unless 0; # No warning.
  print (4 + 2) for 0;    # Warning!


  print (4 + 2) and 0;    # No warning.
  print (4 + 2) or 0;     # No warning.
  print (4 + 2) xor 0;    # Warning.
  print (4 + 2) || 0;     # No warning.
  print (4 + 2) && 0;     # Warning.


<>  $ perl -wle 'print  (4 + 2) * 3;'
<>  Useless use of multiplication (*) in void context at -e line 1.
<>  6
<>  
<>  $ perl -MO=Deparse -e 'print  (4 + 2) * 3;'
<>  print(6) * 3;
<>  -e syntax OK
<>  
<>  perldoc perlfunc:
<>  
<>         Any function in the list below may be used either with or without
<>         parentheses around its arguments.  (The syntax descriptions omit
<>         the parentheses.)  If you use the parentheses, the simple (but
<>         occasionally surprising) rule is this: It looks like a function,
<>         therefore it is a function, and precedence doesn't matter.
<>         Otherwise it's a list operator or unary operator, and precedence
<>         does matter.  And whitespace between the function and left
<>         parenthesis doesn't count--so you need to be careful sometimes:
<>  
<>             print 1+2+4;        # Prints 7.
<>             print(1+2) + 4;     # Prints 3.
<>             print (1+2)+4;      # Also prints 3!
<>             print +(1+2)+4;     # Prints 7.
<>             print ((1+2)+4);    # Prints 7.


Yeah. It fails to explain why while you can make this mistake with any
function in Perl, it only warns for three of them. And most of the time
in a wrong way.


Don't use warnings. Unless you rip out this stupid warning from your
copy of Perl. And I'm not joking.



Abigail
-- 
perl -wlpe '}$_=$.;{' file  # Count the number of lines.


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

Date: Sun, 9 Apr 2006 22:17:02 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: DOS globbing
Message-Id: <e1c16l.1fg.1@news.isolution.nl>

Have fun:

C:> perl -le "while ( glob q(c:/*.sys) ) {print}"
c:/CONFIG.SYS
c:/IO.SYS
c:/MSDOS.SYS

C:> perl -le "while ( glob q(c:\*.sys) ) {print}"
c:\CONFIG.SYS
c:\IO.SYS
c:\MSDOS.SYS

C:> perl -le "while ( glob q(c:\\*.sys) ) {print}"
c:\CONFIG.SYS
c:\IO.SYS
c:\MSDOS.SYS

C:> perl -le "while ( glob q(c:\\\\*.sys) ) {print}"
c:\CONFIG.SYS
c:\IO.SYS
c:\MSDOS.SYS


C:> perl -le "while ( glob q(c:\\\\\*.sys) ) {print}"
c:\\CONFIG.SYS
c:\\IO.SYS
c:\\MSDOS.SYS

C:\Perl>perl -le "while ( glob q(c://*.sys) ) {print}"
c://CONFIG.SYS
c://hiberfil.sys
c://IO.SYS
c://MSDOS.SYS

C:> perl -le "while ( glob q(c:///*.sys) ) {print}"
c:///CONFIG.SYS
c:///hiberfil.sys
c:///IO.SYS
c:///MSDOS.SYS

C:> perl -le "while ( glob q(c:\/*.sys) ) {print}"
c:\/CONFIG.SYS
c:\/hiberfil.sys
c:\/IO.SYS
c:\/MSDOS.SYS

(etc.)

-- 
Affijn, Ruud

"Gewoon is een tijger."


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

Date: Sun, 9 Apr 2006 16:27:54 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Extract range of lines from a text file
Message-Id: <slrne3iv2q.jg5.tadmc@magna.augustmail.com>

Amer Neely <softouch@softouch.on.ca> wrote:

> The problem seems to be that $CustData holds all 5 lines. I need to 
> break out each of the lines into a separate string variable


   my @separate_strings = split /\n/, $CustData;


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


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

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


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