sanket vaidya wrote:
Hi everyone,
Kindly go through the code below. use strict;
use warnings;
sub hello;
my $ref = \&hello;
&{$ref};
sub hello
{
print "hello!!";
}
The output on perl 5.10 is Hello!! Whereas the output on perl 5.6.1 is
Hello!!1
Why two different outputs in two different versions?
From where did "1" come from & how to remove it?

I suspect the 1 is output by something separate from Perl. Try writing
the output to a file instead by rewriting your subroutine as:

sub hello {
  open my $fh, '>', 'test' or die $!;
  print $fh "Hello!!\n";
}

also, you should call the subroutine by reference like this:

my $ref = \&hello;
$ref->();

as the syntax you have chosen is prone to error.

HTH,

Rob

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to