#!/usr/bin/perl 2 3 use strict; 4 use warnings; 5 use diagnostics; 6 7 my %nationality_of = ( 8 'Ovid' => 'Greek', 9 'John Davidson' => 'Scottish', 10 'Tennyson' => 'English', 11 'Poe' => 'Tracky', # Geek? 12 ); 13 14 my @nationalities = @nationality_of( 'Ovid', 'Tennyson' ); 15 print "@nationalities"; 16

This piece of simple code is not compiling for me. This is the error:
Possible unintended interpolation of @nationalities in string at test line 15 (#1)
2 (W ambiguous) You said something like '@foo' in a double-quoted string
3 but there was no array @foo in scope at the time. If you wanted a
4 literal @foo, then write it as \@foo; otherwise find out what happened
5 to the array you apparently lost track of.
6
7 Global symbol "@nationality_of" requires explicit package name at test line 14.
8 syntax error at test line 14, near "@nationality_of( "
9 Global symbol "@nationalities" requires explicit package name at test line 15.
10 Execution of test aborted due to compilation errors (#2)
11 (F) You've said "use strict" or "use strict vars", which indicates
12 that all variables must either be lexically scoped (using "my" or "state"),
13 declared beforehand using "our", or explicitly qualified to say
14 which package the global variable is in (using "::").
15
16 Uncaught exception from user code:
17 Global symbol "@nationality_of" requires explicit package name at test line 14.
18 syntax error at test line 14, near "@nationality_of( "
19 Global symbol "@nationalities" requires explicit package name at test line 15.
20 Execution of test aborted due to compilation errors.
~

Any explanations please, I cannot understand why in the book @nationalities is in double quotes. Thank you.

THANK YOU FOR THE REPLIES.

In reply to Problem with hash slice. by MrSparks

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.