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.
In reply to Doubt in functions by vyeddula
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |