
Laurent_R
Veteran
/ Moderator
Jun 11, 2017, 1:12 AM
Post #7 of 9
(3756 views)
|
Re: [Wildcard] can't declare a simple list from a book example...
[In reply to]
|
Can't Post
|
|
Back to your original post, yes, indeed:
($fred, $barney, $dino) = ("Flintstone", "Geroellheimer", undef); does nothing visible by itself. It only assigns values to the $fred and $baney variables, but you would need to do something with these variables so see an effect. For example, you could print them to the screen (see below). And, if you use warnings (which you should always do), then you need to change the above code line to something like this:
my ($fred, $barney, $dino) = ("Flintstone", "Geroellheimer", undef); If you do that, you'll no longer have the "required explicit package..." warnings, since "my" declares these variables. So the overall fix for your problem might be something like this:
use warnings; my ($fred, $barney, $dino) = ("Flintstone", "Geroellheimer", undef); print "Fred: $fred \n"; print "Barney: $barney \n"; The above code should work without any problem. But you'll get a warning again if you try to print out $dino, because it is now declared, but still undefined. Update: it would help if you said which book exactly (title + edition) you're using.
(This post was edited by Laurent_R on Jun 11, 2017, 1:13 AM)
|