in reply to Nervously....How do I access the Name of a Perl variable?

I'm not aware of any pure Perl way of doing #1. Sorry. For #2, see caller() or __LINE__.
  • Comment on Re: Nervously....How do I access the Name of a Perl variable?

Replies are listed 'Best First'.
Re: Nervously....How do I access the Name of a Perl variable?
by Abigail-II (Bishop) on Jun 11, 2002 at 09:51 UTC
    Well, perl does have the -p option which will throw your Perl program through the C preprocessor....

    You have to be careful though, as the # character also starts a Perl comment.

    Abigail


      Here is a simple example using -P. The program should be run as follows perl -P program.pl and it requires a pre-processor on the target system:
      #!/usr/bin/perl -w use strict; #define TRACE(x) print "$0 line ". __LINE__ .":\t". x ." = ". eval +(x). "\n"; my $foo = 7; TRACE('$foo'); $foo *= $foo; TRACE('$foo'); __END__ Prints: /tmp/test.pl line 8: $foo = 7 /tmp/test.pl line 11: $foo = 49

      --
      John.