Defendore
Defendore

Reputation: 649

What is the output of the following code and is there any significance to Symbol tables?

What will be the output of the following program and Why? is there any significance to symbol table w.r.t to the result?

package Test;

sub func {
  print "First instance\n";
}

sub func {
  print "Second instance\n";
}
1;
#! /usr/bin/perl
# File: script.pl

use Test;
Test::func();

Upvotes: 0

Views: 200

Answers (1)

erickb
erickb

Reputation: 6309

"Second instance\n"

A package/global variable will have an entry in the symbol table, you can try this to verify:

use Test;
Test::func();

for my $entry ( keys %Test:: )
{
    print "$entry\n";
}

Link to reference: http://www252.pair.com/comdog/mastering_perl/Chapters/08.symbol_tables.html

Upvotes: 1

Related Questions