Thursday, May 14, 2009

perl caller

The way caller will show what is there in the array

File: temp.pm
#!/usr/bin/perl

package temp;

sub first_level {

@callerList = caller(0);
$size = scalar @callerList;
print "This is the size $size \n";
for ($index = 0; $index < $size; $index++) {
print "This is the index $index " . $callerList[$index] . "\n";
}

}

1;

File : test.pl
use temp;
print "Started the pgm \n";
temp::first_level();

@callerList = caller(0);
$size = scalar @callerList;
print "This is the size $size \n";
for ($index = 0; $index < $size; $index++) {
print "This is the index $index " . $callerList[$index] . "\n";
}


This is the output
Started the pgm
This is the size 10
This is the index 0 main
This is the index 1 test.pl
This is the index 2 3
This is the index 3 temp::first_level
This is the index 4 1
This is the index 5
This is the index 6
This is the index 7
This is the index 8 0
This is the index 9
This is the size 0

No comments: