diff options
-rw-r--r-- | perl.html.markdown | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/perl.html.markdown b/perl.html.markdown index 93eabea9..17a538e3 100644 --- a/perl.html.markdown +++ b/perl.html.markdown @@ -37,10 +37,14 @@ use warnings; # A scalar represents a single value: my $animal = "camel"; my $answer = 42; +my $display = "You have $answer ${animal}s.\n"; # Scalar values can be strings, integers or floating point numbers, and # Perl will automatically convert between them as required. +# Strings in single quotes are literal strings. Strings in double quotes +# will interpolate variables and escape codes like "\n" for newline. + ## Arrays # An array represents a list of values: my @animals = ("camel", "llama", "owl"); @@ -58,6 +62,18 @@ my $second = $animals[1]; my $num_animals = @animals; print "Number of numbers: ", scalar(@numbers), "\n"; +# Arrays can also be interpolated into double-quoted strings, and the +# elements are separated by a space character by default. + +print "We have these numbers: @numbers\n"; + +# Be careful when using double quotes for strings containing symbols +# such as email addresses, as it will be interpreted as a variable. + +my @example = ('secret', 'array'); +my $oops_email = "foo@example.com"; # 'foosecret array.com' +my $ok_email = 'foo@example.com'; + ## Hashes # A hash represents a set of key/value pairs: |