MC logo

Using Perl Identifiers (Answer)

  Practice Problems

  1. @abc = ("Hi", "there", "how", "are", "you?");
    print "@abc\n";
    Sets the contents of @abc and prints it, giving: Hi there how are you?.
  2. ($abc) = ("Hi", "there", "how", "are", "you?");
    print "$abc\n";
    When assigning a longer list to a shorter, we loose the extra items at the right. Therefore $abc is assigned "Hi", and the program prints Hi.
  3. @abc = ("Hi", "there", "how", "are", "you?");
    print "$abc[2]\n";
    Prints how.
  4. @abc = ("Hi", "there", "how", "are", "you?");
    print "$abc\n";
    Since $abc is a different variable, unrelated to @abc, it is uninitialized and equal to the empty string. Only the newline is printed.

Question Using @ARGV>>