Check syntax question...

B

Bob

I am going through another persons code. I turned on "strict" and
"warnings" and I am not sure what to do about this warning:

"Scalar value @_[0] better written as $_[0] at update_patch.pl line
939."

Should I change it to reflect what is suggested? Why did it suggest
that? I am just a wee learner of Perl.

Robert
 
P

Paul Lalli

I am going through another persons code. I turned on "strict" and
"warnings" and I am not sure what to do about this warning:

"Scalar value @_[0] better written as $_[0] at update_patch.pl line
939."

Should I change it to reflect what is suggested?

Almost certainly yes. We'd have to see the code to be 100% certain, but
the chances of it not being better changed are very unlikely.
Why did it suggest that?

In Perl, $ is used to mean scalar, which is a single value. @ is used to
mean array, a collection of values. The syntax of @array[2,3,4] for
example, means "the set containing the third, fourth, and fifth elements
of @array". The syntax @array[2] means "the set containing the third
element of @array". $array[2], on the other hand, means simply "the third
element of @array". There is almost never a reason to use a collection
containing one element where all you actually need is that one element.
That is what that warning is about.
I am just a wee learner of Perl.

Read up! :) Take a look at
perldoc perlsyn
for the syntax of Perl, and
perldoc perldiag
for a description and explanation of all the warnings you may encounter.


Paul Lali
 
T

Tad McClellan

Bob said:
I am going through another persons code. I turned on "strict" and
"warnings" and I am not sure what to do about this warning:

"Scalar value @_[0] better written as $_[0] at update_patch.pl line
939."

Should I change it to reflect what is suggested?

Yes.


Why did it suggest
that?


Because sometimes it makes a difference.

I am just a wee learner of Perl.


Your Question is Asked Frequently:

What is the difference between $array[1] and @array[1]?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top