On 4/25/05, Manish Sapariya <[EMAIL PROTECTED]> wrote:
> Hello,
> Can somebody explain me the magic here....
>
sub vprint (@) {
# subroutine declaration with prototype
return unless $Utils::verbose;
# exit sub unless $Utils::verbose flag is set
my ($file, $line) = (caller)[1,2];
# take a slice (the second and third items: the file containing
# the package where the subroutine was called, and the line
# number where it was callled) of the list returned by the
# caller() function, and assign the values to $file and $line.
# see perldoc -f caller for details.
my $subr = (caller 1)[3] || 'main';
# take a slice of (only the thrid item) of the list returned
# by caller(1) and assign the value (the subroutine name
# of the subroutine where the current subroutine (vprint)
# was invoked to $subr. (caller 1)[3] is undefined, use
# 'main' instead. see perldoc -f caller for details.
$file =~ s!.*/!!;
# strip everything up to the last '/' character from $file
# in case (caller)[1] is a full path name.
print STDERR "$subr($file:$line): ", @_;
# print the subroutine, file, and line number information,
# along with anything else passed to the sub on STDERR.
}
HTH,
--jay
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>