David le Blanc wrote:

Roughly speaking (ie, without referring to the bible), a block is one or more expressions enclosed in curly braces;


1/3    is an expression.  Result is roughly 0.3333333

{ $a=$b; $name="James"; 1+3 } is a block of three expressions, resulting
in the assignment of two variables.  The scope of these particular variables
will be larger than the block, because they are neither defined as
'local' nor 'my'.

The 'Result' of the block is the result of the last expression, or in
this case, 4.

A code block is not a subroutine and it doesn't have a 'Result'.


( Please dont confuse ( 1,2,4,5 ) with { 1,2,3,4 } as they are
completely different.
The first is a list of 4 values, while the latter is a block of code
which evaluates to
"4".  )

They are *both* a list of four values and the second one is an anonymous hash *not* a code block.



Perl can take expressions in most places however you need to understand how the
expresion gets interpreted by perl.

Eg,

$a = 1+3

The expression (1+3) is evaluated immediately and the result assigned to $a.

$a = { 4,5,6 }

While '{ 4,5,6 }' as a block results to the number 6, the line above
is illegal perl and
will/should fail to compile. (I'll explain later)

That is *not* a code block, it is an anonymous hash and it *will* compile although it will produce a warning if warnings are enabled.


$ perl -MData::Dumper -le' $a = { 4,5,6 }; print Dumper $a'
$VAR1 = {
          '6' => undef,
          '4' => 5
        };

$ perl -Mwarnings -MData::Dumper -le' $a = { 4,5,6 }; print Dumper $a'
Odd number of elements in anonymous hash at -e line 1.
$VAR1 = {
          '6' => undef,
          '4' => 5
        };



John
--
use Perl;
program
fulfillment

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to