Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference of using special variable $_ and @_ in Perl?

Tags:

People also ask

What does @_ do in Perl?

The @_ variable is an array that contains all the parameters passed into a subroutine. The parentheses around the $string variable are absolutely necessary. They designate that you are assigning variables from an array.

What is $_ mean in Perl?

There is a strange scalar variable called $_ in Perl, which is the default variable, or in other words the topic. In Perl, several functions and operators use this variable as a default, in case no parameter is explicitly used.

What is the difference between -> and => in Perl?

-> will resolve inherited methods making it cleaner and more useful for objects. Foo->Bar(); Foo::Bar('Foo'); This means that -> is generally used in instance methods so that the object is passed its self and constructors so the constructors know which package to bless with.


Please explain what exactly the difference of $_ and @_ is in Perl. When to use which, given by example code.