#!/usr/bin/perl ############# # # Examples of perl's numeric formats, from pg 59 of the camel book # ##################3 # When run via a web browser, this tells the browser that # what follows is text. print "Content-type: text/plain\n\n"; $a[0] = 23; # integer $a[1] = 3.14; # float $a[2] = 6.02e23; # scientific $a[3] = 1_234_567.2; # optional underline for legibility $a[4] = 0377; # octal (leading 0) $a[5] = 0xffffff; # hex (leading 0x) $a[6] = 0b_1100_0011; # binary (leading 0b) # Perl's string formats, from pg and pg 403 $a[7] = 'hello $b'; # single quotes don't interpolate $a[8] = "\n say: '$a[7]'\n"; # double quotes interpolate $x, @y, \n, \t, ... $a[9] = q{jim}; # another single quote - {} can be any chars $a[10] = qq!Joe\n!; # another double quote - !! can be any chars $a[11] = George; # a "bareword" unrecognized by perl is converted # to a string - but you don't want to do this. # If warning are enabled, this will fail. # A "Here is" document. # The syntax can be confusing. # Think of the construction # <<"chars" # as standing in for the text which follows # *after* the perl statement which its in finishes. $a[12] = <<"YOUR_END_MARK_HERE"; This is a longer string that extends over several lines and has a carriage return at the end. YOUR_END_MARK_HERE @foo = qw( one two ); # quote-words - same as ('one', 'two') $c = v12.6.234.4; # v (version) strings of 4 unicode "characters". $d = 12.6.234.4; # Same thing. "v" is not needed if periods are used. # Also seen in syntax like "use 5.6.0;" print " ---- a bunch of numbers and strings ----- \n\n"; print " @a \n"; print "printing an array: ", @foo, "\n"; print "interpolating an array: @foo \n"; printf("%vd \n",$c); # "%vd" is the format for v-strings