CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Setting up Eclipse/Epic

 



PapaGeek
User

Aug 10, 2013, 3:55 AM

Post #1 of 14 (1245 views)
Setting up Eclipse/Epic Can't Post

 
Iím a newbie to Perl and Iím using strawberry Perl with Eclipse and Epic as my editing and debugging environment.

My first project is to develop a package that will allow me to retrieve financial information from the web.

The coding is going fairly well, but I have the following issues with the development and debugging environment.

My file layout is currently:

C:\p4\Shared\GetWeb.pm
C:\p4\WebTests\webTest.pl
C:\p4\ WebTests\subtest.pl (A file I just added)

This is what my webTest.pl looks like:


Code
use Modern::Perl '2013'; 
use lib '../shared'; # Shared
use Time::Piece;
use GetWeb;

main();

sub main
{
my %hashedPrices;

my @stockList = ("C","FB","DELL");

%hashedPrices = GetWeb::YahooQuotes(\@stockList);
for my $market (sort keys %hashedPrices)
{
my $LastTrade = $hashedPrices{$market};
print "$market -> $LastTrade\n";
}

%hashedPrices = GetWeb::YahooHistory("C");
for my $tradeDate (sort keys %hashedPrices)
{
my $LastTrade = $hashedPrices{$tradeDate };
print "$tradeDate -> $LastTrade\n";
}
subtest();
}

The code runs and accesses the web properly, but I have the following development problems:

1. I can set breakpoints in webTest.pl and they work fine from Eclipse/Epic.
2. I can set breakpoints in GetWeb.pm, but they are ignored by Eclipse/Epic.
3. When I added the subtest.pl file which merely prints ďHelloĒ, I get the following error:
. . . . a. Undefined subroutine &main::subtest called at C:/p4/WebTests/webTest.pl line 29.

Any help on how to set up my development environment would my appreciated.


(This post was edited by PapaGeek on Aug 10, 2013, 3:58 AM)


FishMonger
Veteran / Moderator

Aug 10, 2013, 6:14 AM

Post #2 of 14 (1241 views)
Re: [PapaGeek] Setting up Eclipse/Epic [In reply to] Can't Post

Where was subtest() defined? I assume it's in GetWeb.pm. Was the sub exported?


PapaGeek
User

Aug 10, 2013, 7:06 AM

Post #3 of 14 (1237 views)
Re: [FishMonger] Setting up Eclipse/Epic [In reply to] Can't Post

No, it is a separate .pl fild in the same directory as the mainline code.

C:\p4\Shared\GetWeb.pm
C:\p4\WebTests\webTest.pl
C:\p4\WebTests\subtest.pl (A file I just added)

The code is very simple, I just wanted to see how to break up my code into multiple file in the same directory.



Code
use Modern::Perl '2013'; 

sub subtest
{
print "Hello\n";
}

As my code grows I'd like to break it up into multiple files.


FishMonger
Veteran / Moderator

Aug 10, 2013, 7:31 AM

Post #4 of 14 (1228 views)
Re: [PapaGeek] Setting up Eclipse/Epic [In reply to] Can't Post

You need to have a statement in webTest.pl that loads subtest.pl so that it can find the subtest() sub. The easiest way to do that would be to add a 'do' statement just after your 'use' statements.

Code
do 'subtest.pl';


The best method would be to put subtest() in a .pm module which exports the sub and load that module via a use statement.


(This post was edited by FishMonger on Aug 10, 2013, 7:33 AM)


Laurent_R
Veteran / Moderator

Aug 10, 2013, 7:39 AM

Post #5 of 14 (1221 views)
Re: [PapaGeek] Setting up Eclipse/Epic [In reply to] Can't Post

Your program cannot know about the subtest subroutine.

You can either change your subtest into a module as follows:


Code
package pack_subtest; 
use Modern::Perl '2013';

use Exporter qw(import);
our @EXPORT=qw /subtest/;

sub subtest
{
print "Hello\n";
}
1;


name it pack_subtest.pm and add the following line in your main program:

Code
use pack_subtest;


Or you could possibly use the old (and, I would think, probably deprecated) way of including subroutines (which I never use and do not really recommend):


Code
do 'subtest.pl';


EDIT: Oops, Fishmonger typed faster than I. Wink


(This post was edited by Laurent_R on Aug 10, 2013, 7:40 AM)


FishMonger
Veteran / Moderator

Aug 10, 2013, 8:21 AM

Post #6 of 14 (1217 views)
Re: [Laurent_R] Setting up Eclipse/Epic [In reply to] Can't Post

We also want to remember/follow best practices.

1) Use proper case when naming a module i.e., lowercase names by convention are reserved for pragmas and CamelCase for regular modules.

Code
package PackSubtest;


2) Export only what you must via @EXPORT and export the rest via @EXPORT_OK.

Code
our @EXPORT_OK = qw/subtest/;


Then:

Code
use PackSubtest qw(subtest);



(This post was edited by FishMonger on Aug 10, 2013, 8:22 AM)


Laurent_R
Veteran / Moderator

Aug 10, 2013, 9:19 AM

Post #7 of 14 (1211 views)
Re: [FishMonger] Setting up Eclipse/Epic [In reply to] Can't Post

You are right. I just wanted to quickly give the minimal amount of changes to have it work the way the OP wanted, but clearly, it does not change much to do it the best way from the outset. Especially, my naming of the package was sloppy and I should have used CamelCase.

As for the export, I used @EXPORT rather than @EXPORT_OK because this module only has one subroutine for the time being, so there is no point of using it if you don't intend to import this subroutine. But you are right, I usually use rather the @EXPORT_OK array, except sometimes for functions that MUST always be used if the module is going to be used. For example, I wrote a module that absolutely needs to be called with the init function the first time the module is used (init_connexion makes the connexion to the database, opens a transaction, does a couple of other small things and returns a connexion id and an error buffer number). I only export systematically init_connexion, which will be needed in all cases, all the other functions that may or may not be useful in the user's program are in the @EXPORT_OK array.


PapaGeek
User

Aug 10, 2013, 9:35 AM

Post #8 of 14 (1207 views)
Re: [Laurent_R] Setting up Eclipse/Epic [In reply to] Can't Post

All of these are great suggestions, and I do appreciate them, but the second question from my original post:

2. I can set breakpoints in GetWeb.pm, but they are ignored by Eclipse/Epic.

is the kicker! How do I get the Eclipse/Epic editor/debugger process to recognize the breakpoints inside the PM files so I can debug them?


Laurent_R
Veteran / Moderator

Aug 10, 2013, 10:35 AM

Post #9 of 14 (1205 views)
Re: [PapaGeek] Setting up Eclipse/Epic [In reply to] Can't Post

I am not using Eclipse, I do not know. It could be that you have to be stepping in the module to be able to set a breakpoint in it. Or try to set a breakpoint on the subroutine name (at least that's what you can do under the Perl debugger: b subname), the program should stopo at the first line of the subroutine;


FishMonger
Veteran / Moderator

Aug 10, 2013, 11:17 AM

Post #10 of 14 (1204 views)
Re: [PapaGeek] Setting up Eclipse/Epic [In reply to] Can't Post

I don't use Eclipse either, so like Laurent, I can't answer that question. That question would be best answered in a forum dedicated to Eclipse.

http://www.eclipse.org/forums/

For my testing/debugging instead of using breakpoints, I use a combination of print, warn and die statements.


PapaGeek
User

Aug 12, 2013, 5:47 AM

Post #11 of 14 (1178 views)
Re: [FishMonger] Setting up Eclipse/Epic [In reply to] Can't Post

This forum is used to post and answer questions, so, since I think I figured this one out myself, let me post what is possibly the answer:

I had to move the PM file from the shared directory into the same directory as the PL file I was debugging. It now stops at the breakpoints I set in the PM file, but still does not stop at the breakpoints I set in the secondary PL file.

Am I right in assuming that the Epic debugger only recognizes only the executed PL file and only PM files that exist in the local directory?


FishMonger
Veteran / Moderator

Aug 12, 2013, 8:18 AM

Post #12 of 14 (1175 views)
Re: [PapaGeek] Setting up Eclipse/Epic [In reply to] Can't Post


Quote
Am I right in assuming that the Epic debugger only recognizes only the executed PL file and only PM files that exist in the local directory?

Possibly but since Laurent and I haven't used Epic, we can't give a definitive answer to that question.


PapaGeek
User

Aug 13, 2013, 11:41 AM

Post #13 of 14 (1164 views)
Re: [FishMonger] Setting up Eclipse/Epic [In reply to] Can't Post

What do you guys use for a debugger? The Eclipse / Epic combo lets you set breakpoints, and when you get to one of them, if you have loaded the PadWalker option, you can then examine all of the variable as they exist at that point.

Still new to Perl, so not sure what else is available for debugging.

I made my previous post to let others know the solution that worked for me.


Laurent_R
Veteran / Moderator

Aug 13, 2013, 11:50 AM

Post #14 of 14 (1163 views)
Re: [PapaGeek] Setting up Eclipse/Epic [In reply to] Can't Post

I am using the Perl debugger, which offers just about everything I want from a debugger, including break points, watch expressions, dumps of complex data structure, various stepping modes, etc.

Just to give you an idea, the quick help of the Perl debugger (Perl version 5.14):


Code
  V [Pk [Vars]]  List Variables in Package.  Vars can be ~pattern or !pattern. 
X [Vars] Same as "V current_package [Vars]". i class inheritance tree.
y [n [Vars]] List lexicals in higher scope <n>. Vars same as V.
e Display thread id E Display all thread ids.
For more help, type h cmd_letter, or run man perldebug for all docs.
DB<1> h
List/search source lines: Control script execution:
l [ln|sub] List source code T Stack trace
- or . List previous/current line s [expr] Single step [in expr]
v [line] View around line n [expr] Next, steps over subs
f filename View source in file <CR/Enter> Repeat last n or s
/pattern/ ?patt? Search forw/backw r Return from subroutine
M Show module versions c [ln|sub] Continue until position
Debugger controls: L List break/watch/actions
o [..] Set debugger options t [expr] Toggle trace [trace expr]
<[<]|{[{]|>[>] [cmd] Do pre/post-prompt b [ln|event|sub] [cnd] Set breakpoint
! [N|pat] Redo a previous command B ln|* Delete a/all breakpoints
H [-num] Display last num commands a [ln] cmd Do cmd before line
= [a val] Define/list an alias A ln|* Delete a/all actions
h [db_cmd] Get help on command w expr Add a watch expression
h h Complete help page W expr|* Delete a/all watch exprs
|[|]db_cmd Send output to pager ![!] syscmd Run cmd in a subprocess
q or ^D Quit R Attempt a restart
Data Examination: expr Execute perl code, also see: s,n,t expr
x|m expr Evals expr in list context, dumps the result or lists methods.
p expr Print expression (uses script's current package).
S [[!]pat] List subroutine names [not] matching pattern
V [Pk [Vars]] List Variables in Package. Vars can be ~pattern or !pattern.
X [Vars] Same as "V current_package [Vars]". i class inheritance tree.
y [n [Vars]] List lexicals in higher scope <n>. Vars same as V.
e Display thread id E Display all thread ids.
For more help, type h cmd_letter, or run man perldebug for all docs.


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives