Like everyone has pointed out "code" tags will make your code clearer.
Here is what I get when I clean out your code
use warnings; use strict; sub AddNumbers { numberList($first_number, $second_number, $third_number, $fourth_n +umber, $fifth_number, $sixth_number) = @_; $add $first_number + $second_number + $third_number + $fourth_numb +er + $fifth_number + $sixth_number; } print "Equals to: &add /n"
And here are the errors that your code generates:
Scalar found where operator expected at temp.pl line 7, near "$add $fi +rst_number" (Missing operator before $first_number?) Global symbol "$first_number" requires explicit package name at temp.p +l line 6. Global symbol "$second_number" requires explicit package name at temp. +pl line 6. Global symbol "$third_number" requires explicit package name at temp.p +l line 6. Global symbol "$fourth_number" requires explicit package name at temp. +pl line 6. Global symbol "$fifth_number" requires explicit package name at temp.p +l line 6. Global symbol "$sixth_number" requires explicit package name at temp.p +l line 6. Global symbol "$add" requires explicit package name at temp.pl line 7. syntax error at temp.pl line 7, near "$add $first_number " Global symbol "$first_number" requires explicit package name at temp.p +l line 7. Global symbol "$second_number" requires explicit package name at temp. +pl line 7. Global symbol "$third_number" requires explicit package name at temp.p +l line 7. Global symbol "$fourth_number" requires explicit package name at temp. +pl line 7. Global symbol "$fifth_number" requires explicit package name at temp.p +l line 7. Global symbol "$sixth_number" requires explicit package name at temp.p +l line 7. Execution of temp.pl aborted due to compilation errors.

Let me try explaining what these errors mean:
Scalar found where operator expected at temp.pl line 7, near "$add $fi +rst_number"

You will see that you have missed out the '='. Perl is telling you that it was looking for some operator but found another variable.
Global symbol "something" requires explicit package name at

Here you need to use 'my' because you have used "strict". If not Perl is going to look for places where this variable has been defined and not finding any will croak.
print "Equals to: &add /n"
First off new line is '\n' and not'/n'. I am unclear on what you expect printed here considering you have not called 'AddNumbers'

Here is your code with the above mentioned errors corrected:
use strict; use warnings; sub AddNumbers { my ($first_number, $second_number, $third_number, $fourth_number, +$fifth_number, $sixth_number) = @_; my $add = $first_number + $second_number + $third_number + $fourth +_number + $fifth_number + $sixth_number; return $add; } my $sum = AddNumbers( 1, 2, 3, 4, 5, 6 ); print "The sum of input numbers equals to: $sum \n";

You must note that it is not a good idea to use a static number of params like you have. This will limit your method to a particular number of input parameters (in this case 6). The fact that Perl always passes parameters as a list can be exploited and allows for an easy way to implement polymorphism.

This is where the solution given by Anonymous Monk comes in. You will notice that that solution will work for any number of parameters.

In reply to Re: Subroutine help by tmharish
in thread Subroutine help by hackernet1337

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.