Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Re: Question about || (was REGEXP removing - il- - -b-f and - il- - - - f)
On 4/27/05, Peter Rabbitson <rabbit@rabbit.us> wrote: 
>=20
> Why is that? :) I was actually going to post a question about ambiguity
> syntax later, but here it is anyway. Are the following 4 equivalent?
>=20

No.

> 1)
> if ($b) {
>   $a =3D $b;
> }
> else {
>   $a =3D $c;
> }

Pretty self explanatory

> 2)
> $a =3D $b or $c;

"=3D" has higher precedence than "or", so it parses as "($a =3D $b) or
$c".  $a will never equal $c.  Something else will equal either the
return value of ($a =3D $b)  or $c.

> 3)
> $a =3D $b || $c;
>=20

Same as 1) because || has higher precedence than =3D.  So ti works in
this case.  But be careful with things like '$a =3D $b || $c =3D $d',
which will parse as '$a =3D ($b || $c) =3D $d'.

> 4)
> $a =3D $b ? $b : $c;
>=20

Same as 1)

> Also there was an example on the web that completely threw me off. Althou=
gh
> this works:
>=20
> local ($/);
>=20
> ,I have no idea how it undefs $/. Points to a good reading on the
> subject are equally appreciated.
>=20

local declares a variable in a particular scope.  It saves the current
value of the variable, if any, and reinitializes the variable for the
duration of the curent scope (and only in the current scope).  In nine
case out of ten, local will be functionally equivalent to using my,
but It is exclusively for use with globals and package globals; trying
to use it with a normal lexical (I.e. "my") variable will throw an
exception.  See perldoc perlvar for details, and why you want to use
local instead of undef on built-ins (i.e., why 'local $/' is better
than 'undef $/' or '$/ =3D '' ').

HTH,

--jay

Report this thread to moderator Post Follow-up to this message
Old Post
Jay Savage
04-27-05 08:56 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:35 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.