3

Having some problems with Perl debugger in Eclipse and PadWalker. Only used it for simple one-file scripts before. Variables declared using "my". They appear fine in the debugger "variables" window.

Now I am using someone else's more complicated script and I don't see the variables declared using "our". To investigate, I boiled it down to one very simple example

junk.pl:

use strict;
use warnings;

require 'junk2.pl';

package Junk;
my $simon = "SOMETHING";
print "JUNK  " . $Junk2::james . "\n";
print "JUNK  " . $simon . "\n";

junk2.pl:

package Junk2;
our $james;
$james = "FOO";

1;

Stepping through the code, the vairable my $simon displays in the debugger window fine but variable our $james does not. The debugger is working OK: the program runs and the output window shows the correct output... it's just the variables window that fails to show $james.

The screen shot below demonstrates the problem. As you can see the variable $james from the Junk2 package prints ok, but does not appear in the variables display.

View of IDE debugger with no package variables

Been searching a while for a solution but can't find anything that matches well... any ideas?

EDIT: Have found out that I can "see" the package variables if I use the Perl debugger: View of cmd line debugger.

Is there a way to have the same output in a friendly manner in the IDE like padwalker shows?

Thank you to guys who have answered so far :)

ysth
  • 96,171
  • 6
  • 121
  • 214
Jimbo
  • 4,352
  • 3
  • 27
  • 44
  • 3
    `our` variables are package variables, i.e., not lexically scoped and not stored on the pad. – mob Aug 22 '13 at 15:07
  • @mob, thanks. do you know if there are any other debug tools/plugins I can use to view these variables in the same way as the lexically scoped vars? – Jimbo Aug 22 '13 at 15:12
  • I'm not familiar with how to use Eclipse with Perl. Can you add the variable `$Junk2::james` to the variable list? Even a small program will have many global variables defined in many different packages; Eclipse probably wouldn't want to add them all to the variables watchlist by default. – mob Aug 22 '13 at 15:29
  • @mob, Variables declared with `our` are lexical variables, though those lexical variables are aliased to package variables. – ikegami Aug 22 '13 at 16:16

3 Answers3

5

You can toggle viewing local and global variables under the variables view menu. Variables declared with our are outside of the local scope, and are therefore visible when the global variables option is selected. (I am running eclipse 4.2.1)

To access the variables view menu click the small down arrow on the top right of the variables pane.

deweytew
  • 49
  • 1
  • 3
4

Variables declared with our are lexical variables, aliased to package variables (thank you @ikegami for the correction):

our makes a lexical alias to a package variable of the same name in the current package for use within the current lexical scope.

brian d foy has a recent post discussing symbol tables.

The short answer is, you access package variables by looking at the package's symbol table.

In addition, PadWalker has a peek_our method. Package::Stash provides other useful helpers.

Sinan Ünür
  • 116,958
  • 15
  • 196
  • 339
  • Thanks for taking the time to answer. Are there any plugins that would allow me to "see" package variables in the same way that I can view the lexical-scoped variables in the variables window? – Jimbo Aug 22 '13 at 15:53
  • 1
    Sorry, can't help with that. I am not inclined to go near Eclipse. – Sinan Ünür Aug 22 '13 at 16:01
  • Variables declared with `our` are lexical variables, though those lexical variables are aliased to package variables. – ikegami Aug 22 '13 at 16:16
2

In the Eclipse Debug Configuration at -X to the Perl command line to show current package variables.

Edit:

In this case you might need to use the -V command instead. See http://perldoc.perl.org/perldebug.html

Edit:

It would probably be easier to just assign the Junk2::James variable to local variable.

my $james = $Junk2::james;

gmlacrosse
  • 362
  • 2
  • 8
  • Hi, thanks for taking the time to answer. Unfortunately, this did not add the package variables :-S – Jimbo Aug 22 '13 at 15:52
  • You might have play around with the perl debugger commands.http://perldoc.perl.org/perldebug.html – gmlacrosse Aug 22 '13 at 15:56
  • Thanks, just doing that. Looks like I can see the package variables using the command line debugger... but what I'd really like is to be able to see them in the IDE :) – Jimbo Aug 22 '13 at 15:59
  • In the IDE there is an option to change the Debug Configuration. In eclipse this is a down arrow by the Debug button. There will be a text box for adding Perl command line options. – gmlacrosse Aug 22 '13 at 16:00
  • That's what I tried. It did't let the debugger show the package variables I'm afraid. Although the extra variable `$[` was shown... not sure why? – Jimbo Aug 22 '13 at 16:04
  • Are you using the epic plugin? – gmlacrosse Aug 22 '13 at 16:07
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/36038/discussion-between-jimbo-and-gmlacrosse) – Jimbo Aug 22 '13 at 16:10