Check syntax question...

Discussion in 'Perl Misc' started by Bob, Jun 21, 2004.

  1. Bob

    Bob Guest

    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
    Bob, Jun 21, 2004
    #1
    1. Advertising

  2. Bob

    Paul Lalli Guest

    On Mon, 21 Jun 2004, Bob wrote:

    > 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
    Paul Lalli, Jun 21, 2004
    #2
    1. Advertising

  3. Bob <> wrote:
    > 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]?


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Jun 22, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. gabriele renzi
    Replies:
    2
    Views:
    189
    gabriele renzi
    Dec 31, 2005
  2. Ken Bloom
    Replies:
    3
    Views:
    182
  3. Good Night Moon
    Replies:
    9
    Views:
    258
    Rick DeNatale
    Jul 25, 2007
  4. Jacob Grover
    Replies:
    5
    Views:
    299
    Jacob Grover
    Jul 18, 2008
  5. Mark Richards
    Replies:
    3
    Views:
    297
    Tad McClellan
    Nov 18, 2007
Loading...

Share This Page