What is the difference between Perl’s $_ and @_ variables?

1 Answers
Answered by suresh

Difference between Perl's $_ and @_ Variables | Interview Question

Difference between Perl's $_ and @_ Variables

In Perl programming, $_ and @_ are special variables that serve different purposes:

  • $_: This variable is a default input and pattern-searching space. It is used by various functions like print, foreach, sort, etc., where no explicit variable is specified. It is commonly used as an implicit variable in many Perl operations.
  • @_: This variable is an array that holds the arguments passed to a subroutine in Perl. When a subroutine is called, the arguments are stored in @_ for the duration of that subroutine call. This array allows the subroutine to access and manipulate the arguments passed to it.

Understanding the usage and differences between $_ and @_ variables is crucial for effective Perl programming.

Answer for Question: What is the difference between Perl’s $_ and @_ variables?