Thursday, January 31, 2008

Learning Perl, 4th Edition Notes 0x1

Learning Perl, 4th Edition Notes 0x1 by DaNmarner * Perl computes with double-precision floating-point values. * Octal (base 8) is leaded by 0, while hexadecimal leaded by 0x and binary 0b. * For clarity, underscore within integer literals is available. So is for non-decimal literals. * Use perl string to create, scan, and manipulate raw binary data. * Unlike in double quote, any characters other than a single quote or a backslash between the single quote marks stands for itself inside a string. * Numeric Operater: +-*/% String Operater: .x * Using Build-In Warnings Turn on in command line:
$perl -w program
or, for more details:
$perl -Mdiagnostics ./program
Request on #! line:
#!/usr/bin/perl use progma
#!/usr/bin/perl use warnings;
or, for more details:
#!/usr/bin/perl use digonostics;
* Output with print
print list;
list is a series of scalars seperated by commas. * Double-quoted string literal is subject to variable interpolation. Curly braces can be used as the delimiter of variable names. For instance:
print "This is $whats"; #print the value of $whats print "This is ${what}s" #print the value of $what
* Perl has the same precedence and associativity as C. * Numeric and string comparison operators: == eq (equel) != ne (not equel) <> gt (greater than) <= le (less or equel) >= ge (greater or equel) * For boolean values, 0 or empty string means false, other number or string means true; * reads the next complete text line from standard input. New line included. * Use chomp to remove the newline character from a string, common used like this: chomp ($line=); * The value undef exists in those unassigned variables. returns undef is there's no more input is there(end-of-file or Ctrl+D).

4 comments:

Randal L. Schwartz said...

"So is for non-decimal literals that longer than 4 characters." - Where did "4" come from? You can use it for even shorter things. 0xA_B is a legal hex value.

DaNmarner said...

I found it on the book, which is contrast to practice.

Maybe the authors mean that when we use this feature, we are looking at something at least like this 0x00, which counts for 4 characters.

Thank U!

Randal L. Schwartz said...

The exact text from my book is "When a non-decimal literal is more than about four characters long, it may be hard to read." So it's not saying you can't use it for something that's only 2 characters... there's just no point to it. :) Your post implied that you can't use it for shorter.

DaNmarner said...

OOPS. I've corrected that.
Again, thanks.