In the following in Perl script:
$a=apple
$b=orange
if ($?==0) {
# do something
}
What does $?
mean here?
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.
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.
$? 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).
$ is for scalar variables(in your case a string variable.) @ is for arrays.
This is the status returned by the last system operation, pipe, or backtick operation. See reference perlvar.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With