Hi lina,
you could also use:
no strict 'vars' i.e:
#!/usr/bin/perl
use strict;
use warnings;
sub add
{
no strict 'vars'; # added
$results = $_[0] + $_[1];
print "The result was: $results\n";
}
add(1,2); # print "The result was: 3"
__END__
However, it's a good practice to always use "my" for your variables.
Please check **perldoc strict** for more explanations.
On Mon, Feb 13, 2012 at 5:06 PM, lina <[email protected]> wrote:
> On Mon, Feb 13, 2012 at 11:49 PM, Martin Wildgruber <[email protected]>
> wrote:
> > Hi,
> >
> > try:
> >
> > my $results = $_[0] + $_[1];
>
> thanks,
> Before I was confused the use of "my"
>
> Best regards,
> >
> > mit freundlichen Grüßen
> > Martin Wildgruber
> >
> > On 13.02.2012, at 16:43, lina wrote:
> >
> >> Hi,
> >>
> >> #!/usr/bin/perl
> >>
> >> use strict;
> >> use warnings;
> >>
> >> sub add
> >> {
> >> $results = $_[0] + $_[1];
> >> print "The result was: $results\n";
> >> }
> >>
> >> add(1,2)
> >>
> >> $ ./subroutines_examples.pl
> >> Global symbol "$results" requires explicit package name at
> >> ./subroutines_examples.pl line 8.
> >> Global symbol "$results" requires explicit package name at
> >> ./subroutines_examples.pl line 9.
> >> Execution of ./subroutines_examples.pl aborted due to compilation
> errors.
> >>
> >> How to adjust the strict in this situations, why we use strict?
> >>
> >> Thanks with best regards,
> >>
> >> --
> >> To unsubscribe, e-mail: [email protected]
> >> For additional commands, e-mail: [email protected]
> >> http://learn.perl.org/
> >>
> >>
> >
>
> --
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> http://learn.perl.org/
>
>
>
--
Tim