On Tue, Nov 12, 2002 at 09:03:30PM +0100, Angel Faus wrote:
> This is just a tentative draft, so feel free to delete/add at your own 
> taste.
> 
> Does it look ok? Any comments? (including grammar errors, of course)

I've tweaked the first bit on literal integers a bit, see what you
think.


=subsection Literal Values

=head1 Literal numbers

=head2 Integers

There are many ways to specify literal numeric values in perl, but they
default to base 10 for input and output.  Once the number has been read
by perl it becomes just a magnitude.  That is it loses all trace of the
way it was originally represented and is just a number.  This code for
instance prints the literal value 14.

 my $x = 14;   # stores the integer 14 in $x
 print $x;

You can represent the literal value in any other base, using the
C<radix:dddddddd> syntax.

For example:

 my $i = 2:101110;           # binary
 my $j = 3:1210112;          # tertiary
 my $k = 8:1270;             # octal

Printing these would give 46, 1310, and 696 respectively.  When the base
is greater than 10, there is a need to represent digits that are greater
than 9.

You can do this in two ways:

=over

=item *

Alphabetic characters: Following the standard
convention, perl will interpret the A letter as the digit 10,
the B letter as digit 11, and so on.

 my $l = 16:1E3A7;           # hexadecimal

=item *

Separating by dots: You can also write each digit in
its decimal representation, and separate digits using the
C<.> character.

 my $m = 256:255.255.255.0;  # 256-base

=back

For example, the integer 30 can be written in hexadecimal
base in two equivalent ways:

  my $x = 16:1D
  my $x = 16:1.14

These two representations are incompatible, so writing
something like C<16:D.13> will generate a compile-time error.

Finally, you can create negative integers by prepending the
C<-> character.

For example:

 my $x = 18;
 my $y = -18;


andrew
-- 
Leo: (July 23 - Aug. 22)
The only thing that keeps you from realizing your potential is the
depressing awareness that it probably wouldn't take much time or effort.

Attachment: msg24007/pgp00000.pgp
Description: PGP signature

Reply via email to