vyeddula has asked for the wisdom of the Perl Monks concerning the following question:
Hi perl monks.I am new to perl programming .I am a beginner.Here is my first question
#!/usr/bin/perl use strict; use warnings; my $variable=total(1,2,3); print"the variable is :$variable\n"; sub total { my $element=0; foreach (@_) { $element=$element+$_; } element; } Output is: The variable is : 6 Now i changed the code to #!/usr/bin/perl use strict; use warnings; my $variable=total(1,2,3); print"the variable is :$variable\n"; sub total { my $element=0; foreach (@_) { $element=$element+$_; } element; print"the value of element is:$element\n"; } The output is the value of element is:6 the variable is :1 why the variable in this case is not showing as 6 is my question.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Doubt in functions
by BrowserUk (Patriarch) on Jul 06, 2012 at 00:28 UTC | |
|
Re: Doubt in functions
by toolic (Bishop) on Jul 06, 2012 at 00:50 UTC | |
by vyeddula (Acolyte) on Jul 06, 2012 at 02:42 UTC | |
|
Re: Doubt in functions
by monsoon (Pilgrim) on Jul 06, 2012 at 00:18 UTC | |
by ww (Archbishop) on Jul 06, 2012 at 00:55 UTC |