[27748] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9135 Volume: 10

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

Date: Sun, 9 Apr 2006 08:05:04 -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: 9135

Today's topics:
        A problem with precedence (Mark Hobley)
    Re: A problem with precedence <rwxr-xr-x@gmx.de>
    Re: A problem with precedence <anfi@priv.onet.pl>
        ANNOUNCE: Set::Array V 0.13 <ron@savage.net.au>
    Re: Extract range of lines from a text file <softouch@softouch.on.ca>
    Re: fork and taint <no@thanks.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 09 Apr 2006 13:07:36 GMT
From: markhobley@hotpop.deletethisbit.com (Mark Hobley)
Subject: A problem with precedence
Message-Id: <ipbng3-cpo.ln1@neptune.markhobley.yi.org>
Keywords: operator,precedence,perl,problem,add,multiple,times,divide,subtract,brackets 

The following statement gives a result of 10, which is what I expect, because 
multiplication has a higher precedence than addition:

print 4 + 2 * 3;   # 10

I now add brackets to change the precedence:

print (4 + 2) * 3; # This unexpectedly gives 6

Reversing the calculation:

print 3 * (4 + 2); # This gives 18, as expected

Why do I get the answer 6 to (4 + 2) * 3?

-- 

Mark Hobley
393 Quinton Road West
QUINTON
Birmingham
B32 1QE

Telephone: (0121) 247 1596
International: 0044 121 247 1596

Email: markhobley at hotpop dot donottypethisbit com

http://markhobley.yi.org/



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

Date: Sun, 9 Apr 2006 15:21:01 +0200
From: "Lukas Mai" <rwxr-xr-x@gmx.de>
Subject: Re: A problem with precedence
Message-Id: <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.

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

HTH, Lukas


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

Date: Sun, 09 Apr 2006 15:27:22 +0200
From: Andrzej Adam Filip <anfi@priv.onet.pl>
Subject: Re: A problem with precedence
Message-Id: <87zmiuswud.fsf@anfi.homeunix.net>

markhobley@hotpop.deletethisbit.com (Mark Hobley) writes:

> The following statement gives a result of 10, which is what I expect, because 
> multiplication has a higher precedence than addition:
>
> print 4 + 2 * 3;   # 10
>
> I now add brackets to change the precedence:
>
> print (4 + 2) * 3; # This unexpectedly gives 6

It is interpreted as 
(print(4+2))*3

> Reversing the calculation:
>
> print 3 * (4 + 2); # This gives 18, as expected
>
> Why do I get the answer 6 to (4 + 2) * 3?


-- 
[pl2en Andrew] Andrzej Adam Filip : anfi@priv.onet.pl : anfi@xl.wp.pl
http://anfi.homeunix.net/


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

Date: Sun, 9 Apr 2006 04:25:39 GMT
From: Ron Savage <ron@savage.net.au>
Subject: ANNOUNCE: Set::Array V 0.13
Message-Id: <IxGLEt.1CFD@zorch.sf-bay.org>

The pure Perl module Set::Array V 0.13
is available immediately from CPAN,
and from http://savage.net.au/Perl-modules.html.

On-line docs, and a *.ppd for ActivePerl are also
available from the latter site.

An extract from the docs:

0.13  Sun Apr 09 13:58:00 2006
	- Incorporate the patch supplied by Marke, with thanks. Now the method 	
'difference' returns the objects in the difference, and not the stingified
versions of those objects.
		Also, Marke's test has been added to test.t.
		Note: The undocument method 'complement' has not been updated. Email me
suggestions if
		o You know exactly what it ought to do
		o How it differs from calling 'difference' with the $reversed flag set





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

Date: Sun, 09 Apr 2006 04:07:33 -0400
From: Amer Neely <softouch@softouch.on.ca>
Subject: Re: Extract range of lines from a text file
Message-Id: <ag3_f.64570$fd.52193@read2.cgocable.net>

Amer Neely wrote:
> This is driving me nuts.
> 
> I'm walking through a mailbox file, and want to pull out specific lines 
> from each message. The body of each message is in a similar format, 
> having been generated by a script.
> 
> I'm doing OK except for one particular block of lines, the customer 
> address data. There is a blank line before and after this block. Example:
> 
> Transaction Time: 18:45:55
> 
> Amer Neely
> POB 1481 Station Main
> North Bay ON
> P1B 8K7
> CANADA
> 
> 123-456-7890
> 
> I've managed to get the 5 lines into a string using this code:
> 
> while <IN>
> {
> 
> # bunch of other comparisons deleted
> 
> if (/^Transaction Time:/ ... /^\d\d\d-\d\d\d-\d\d\d\d$/)
> {
> $CustData = $_;
> $CustData =~ s/^Transaction Time:.+//; # lose the beginning pattern
> $CustData =~ s/^\d\d\d-\d\d\d-\d\d\d\d$//; # lose the ending pattern
> next if ($CustData =~ m/^$/); # skip the blank lines
> $CustData =~ s/\n//g; # get rid of blank lines. don't think this working
> print "\t$CustData\n";
> }
> }
> close IN;
> print "\nAll done.\n";
> 
> 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 so as to 
> populate a database field. This is what has me stumped. Sure would 
> appreciate some light on this.
> 

The closest I've gotten so far is with the following code.

   if (/^Transaction Time:/ ... /^\d\d\d-\d\d\d-\d\d\d\d$/)
   {
		$CustData = $_;
		$CustData =~ s/^Transaction Time:.+//;
		$CustData =~ s/^\d\d\d-\d\d\d-\d\d\d\d$//;
		next if ($CustData =~ m/^$/);
		$CustData =~ s/\n//g;
		#print "$CustData\n";
		(@CustData) = split(/\n/,$CustData);
		
		my $addcounter=0;
		foreach (@CustData)
		{
			$addcounter++;
			print "\t[$addcounter] $_\n";
		}
	}

Bear in mind this block is in the middle of a message, so there is more 
text before and after this.

But this puts the whole $CustData string (all 5 or 6 lines) into 
$CustData[0], so it's ignoring the split.

-- 
Amer Neely
Home of Spam Catcher
W: www.softouch.on.ca
E: trudge@softouch.on.ca
Perl | MySQL | CGI programming for all data entry forms.
"We make web sites work!"


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

Date: Sun, 9 Apr 2006 11:10:37 +0200
From: Asterbing <no@thanks.com>
Subject: Re: fork and taint
Message-Id: <MPG.1ea2edf4fe4281ff9897de@news.tiscali.fr>

In article <MPG.1ea243ecd65a90ec9897dd@news.tiscali.fr>, no@thanks.com 
says...
> In article <49qjpvFq2ftaU1@individual.net>, noreply@gunnar.cc says...
> > That script runs fine with my IndigoPerl build of Perl (5.8.6).
> > 
> 
> Well, on my side, I'm using ActivePerl 5.8.7 build 815 and this script 
> works fine if not in taint mode only :-(
> 

Goog news : just updated to ActiveState ActivePerl 5.8.7.817 for Win32 
and the problem is gone using the test script (not tested alsewhere at 
this time). So, maybe a build 815's bug.


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

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


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