Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does a dollar sign followed by a question mark mean in Perl?

Tags:

perl

In the following in Perl script:

$a=apple
$b=orange

if ($?==0) {
  # do something
}

What does $? mean here?

like image 977
tweakmy Avatar asked Jun 09 '11 02:06

tweakmy


People also ask

What does question mark mean in Perl?

Perl defines a consistent extension syntax for regular expressions. The syntax is a pair of parentheses with a question mark as the first thing within the parentheses (this was a syntax error in older versions of Perl). The character after the question mark gives the function of the extension.

What does dollar sign mean in Perl?

Array Variables The dollar sign ($) is used to refer a single element of an array with the variable name followed by the index of the element in square brackets. Here is an example of how to use an array variable: Perl.

What is $? Used for?

$? is used to find the return value of the last executed command. Try the following in the shell: ls somefile echo $? If somefile exists (regardless whether it is a file or directory), you will get the return value thrown by the ls command, which should be 0 (default "success" return value).

What is the difference between and in Perl?

$ is for scalar variables(in your case a string variable.) @ is for arrays.


1 Answers

This is the status returned by the last system operation, pipe, or backtick operation. See reference perlvar.

like image 75
James McLeod Avatar answered Sep 20 '22 16:09

James McLeod