Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • I was really looking for 'quotemeta'. Yes, array elements should be specified as $foo[N] and not @foo[N], I could not really figure out the difference between the two.It will be helpful if you can point out the differences. Commented Oct 21, 2015 at 10:34
  • Thanks for including the actual quotemeta definition from the documentation. +1 for that. Commented Oct 21, 2015 at 10:36
  • 1
    @user3687023 $foo[n] is the nth element of array @foo, and @foo[n] is an array slice, it's a new array with one element. Try running perl -MO=Deparse,-q -le '@F=("foo"); print "@F[0]"'. You will see that @F[0] is actually join($", @F[0]). This sort of thing is why it's always a good idea to use warnings;. The code above produces this warning: Scalar value @F[0] better written as $F[0] at -e line 1.. Commented Oct 21, 2015 at 10:41
  • In perl the "sigil" ($, @, % etc.) denotes what data type you expect out of the thing. For a single scalar therefore, it's always $ - $value, $array[$index] or $hash{$key}. Perl knows what it is, because of the type of bracket you're using (if any), not by the sigil. It's perfectly valid to write @array[1..3] (because you're after multiple scalars). Or @hash{("key1", "key2", "key3")} to get a list of values matching the designated keys. Commented Oct 21, 2015 at 11:44