summaryrefslogtreecommitdiffhomepage
path: root/perl.html.markdown
diff options
context:
space:
mode:
authorDan Book <grinnz@gmail.com>2017-05-18 06:40:15 -0400
committerven <vendethiel@hotmail.fr>2017-05-18 12:40:15 +0200
commit6e3d29f036f9ede844f17e36e764b685d046adf9 (patch)
tree73389118326747b0188f73d33adbd27da41e8883 /perl.html.markdown
parenta5833175beb6fea9a2950a2a234e51e06ace3ed9 (diff)
[perl/en] Use more single quotes and explain single vs double quotes (#2710)
* [perl/en] Explain single vs double quotes Explains an example of variable interpolation and escape codes in a double quoted string. * add section about interpolating arrays and email in double quotes trap
Diffstat (limited to 'perl.html.markdown')
-rw-r--r--perl.html.markdown16
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: