Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > split a big program into multiple files

Reply
Thread Tools

split a big program into multiple files

 
 
xhoster@gmail.com
Guest
Posts: n/a
 
      06-08-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Hi,
>
> my program is getting big and I'd like to split it into multiple files,
> something like C guys do.


Why? Is it so big that it is crashing your favorite text editor?

>
> main.pl
>
> include file1.pl
> include file2.pl
>
> etc
>
> I tried both do and require but they doesn't work as I expect:
>
> I can't use the global variables I declare into main for the subrutines
> declared into other files.


I assume that by "global" you mean file-level lexicals.

Generally, you are supposed to pass arguments into subroutines, not pick
them up randomly from the symbol table/pad.

> How can I do?


If you don't want to experience the benefits of using file-level lexicals,
then don't use them. Use package variables instead (or much better,
redesign your program into multiple files along lines such that you don't
need variables to cross the boundaries.)

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
 
 
 
filippo2991@virgilio.it
Guest
Posts: n/a
 
      06-08-2006
Hi,

my program is getting big and I'd like to split it into multiple files,
something like C guys do.

main.pl

include file1.pl
include file2.pl

etc

I tried both do and require but they doesn't work as I expect:

I can't use the global variables I declare into main for the subrutines
declared into other files. How can I do?

Thanks,

Filippo

 
Reply With Quote
 
 
 
 
John Bokma
Guest
Posts: n/a
 
      06-08-2006
(E-Mail Removed) wrote:

> Hi,
>
> my program is getting big and I'd like to split it into multiple files,
> something like C guys do.
>
> main.pl
>
> include file1.pl
> include file2.pl
>
> etc
>
> I tried both do and require but they doesn't work as I expect:


What did you expect?

> I can't use the global variables I declare into main for the subrutines
> declared into other files. How can I do?


Best option would be to group functionality into Perl modules. Instead of
global variables you might want to create objects and initialize them with
those "global" settings.

Might sound as a lot of extra work, but in the end you have a piece of
work that is much easier to maintain.

Also, while grouping functionality, you might keep a close eye on CPAN.
Maybe someone has already written a module that can replace a part of your
code and it might be better to use the CPAN one, especially if it's a
module that is used by many.


--
John Bokma Freelance software developer
&
Experienced Perl programmer: http://castleamber.com/
 
Reply With Quote
 
filippo
Guest
Posts: n/a
 
      06-08-2006
ok John and Xho, you convinced me

In fact I have just a couple of global variables so I can easily
redesign my subroutines to manage these as arguments.

Which is the best method to have a C-like splitting method?

Thanks for your help.

Filippo

 
Reply With Quote
 
Josef Moellers
Guest
Posts: n/a
 
      06-09-2006
filippo wrote:
> ok John and Xho, you convinced me
>
> In fact I have just a couple of global variables so I can easily
> redesign my subroutines to manage these as arguments.
>
> Which is the best method to have a C-like splitting method?


What on earth is a "C-like splitting method"?
In C (and in Perl, and in Modula2, and in any other language that allows
to spread source code over more than a single source file), you split by
grouping things that belong together.

When using #include, you put only definitions (types, structures,
function prototypes, constants) into the files that are included.
Otherwise you put code that belongs together into a C source file and
compile each source file independently into object files which are then
linked together into an executable. The .h-files included provide some
glue between these source files.
--
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett

 
Reply With Quote
 
filippo
Guest
Posts: n/a
 
      06-09-2006

Josef Moellers ha scritto:

ok, you're right.

My application is a Tk GUI based perl program to manage a touristic
campsite. I have some windows:

Main Menu
createGroup
manageGroup
Bill
others (tools)

and I want to split such a big code (~10.000rows) into separate files.
I have no global variables (no more), just subroutines: more or less a
main subroutine plus a couple of service for each windows. Which is the
'best' method to split my program?

Thanks,

Filippo

 
Reply With Quote
 
Josef Moellers
Guest
Posts: n/a
 
      06-09-2006
filippo wrote:
> Josef Moellers ha scritto:
>
> ok, you're right.
>
> My application is a Tk GUI based perl program to manage a touristic
> campsite. I have some windows:
>
> Main Menu
> createGroup
> manageGroup
> Bill
> others (tools)
>
> and I want to split such a big code (~10.000rows) into separate files.
> I have no global variables (no more), just subroutines: more or less a
> main subroutine plus a couple of service for each windows. Which is the
> 'best' method to split my program?


It's indeed probably the most complicated task: to decide which
functions should be grouped together.
I'm not sure if there is a clean-cut approach to do this.

Maybe you could group according to "window"?

Josef
--
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett

 
Reply With Quote
 
filippo
Guest
Posts: n/a
 
      06-09-2006
I know more or less how to split. I'd like to know the best way to
import. I know the 'do' way, are there problems to do this using do?

Thanks,

Filippo

 
Reply With Quote
 
Josef Moellers
Guest
Posts: n/a
 
      06-09-2006
filippo wrote:
> I know more or less how to split. I'd like to know the best way to
> import. I know the 'do' way, are there problems to do this using do?


Oh, sorry for the misunderstanding.

As for the technicality: I really don't know what's the best way to do.
I usually use "use" which is based on "require" which is based on "do".

Hopefully others know better.

Josef
--
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett

 
Reply With Quote
 
Ben Morrow
Guest
Posts: n/a
 
      06-09-2006

Quoth "filippo" <(E-Mail Removed)>:
> I know more or less how to split. I'd like to know the best way to
> import. I know the 'do' way, are there problems to do this using do?


The modern way is to use 'use'. Read perlmod and perlnewmod.

Ben

--
Musica Dei donum optimi, trahit homines, trahit deos. |
Musica truces mollit animos, tristesque mentes erigit.|(E-Mail Removed)
Musica vel ipsas arbores et horridas movet feras. |
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
split a big program into main + (optional) advanced Freddie Perl Misc 9 09-10-2009 07:08 PM
GIDS 2009 .Net:: Save Big, Win Big, Learn Big: Act Before Dec 29 2008 Shaguf ASP .Net 0 12-26-2008 09:29 AM
GIDS 2009 .Net:: Save Big, Win Big, Learn Big: Act Before Dec 29 2008 Shaguf ASP .Net Web Controls 0 12-26-2008 06:11 AM
GIDS 2009 Java:: Save Big, Win Big, Learn Big: Act Before Dec 29 2008 Shaguf Python 0 12-24-2008 07:35 AM
Text files read multiple files into single file, and then recreate the multiple files googlinggoogler@hotmail.com Python 4 02-13-2005 05:44 PM



Advertisments