in reply to How's My Style Now?

Maybe you have a reason for it, but nowadays require'ing .pl files looks somewhat antiquated. Libraries should end up as modules to be use()d. You get to choose which subroutines pollute your namespace (via the Exporter module). You have a clean interface (where someone could look at the module and know which subroutines are internal and which are for other modules or scripts to use)

If you really need the comments where a function is from, modules also give you a fitting (explicit) syntax. Instead of

get_general_text('musing_cat',1); # center.pl

you could write

center::get_general_text('musing_cat',1);

This way the interpreter will correct you if get_general_text were in header.pm instead

Replies are listed 'Best First'.
Re^2: How's My Style Now?
by duelafn (Parson) on Feb 06, 2010 at 15:16 UTC

    I second the module suggestion and sdd a couple of things to jethro's comments.

    When you do create modules, do not use lower-case module names. Lower-case names are (by convention) reserved for pragmatic modules (in effect compiler directives). Additionally, placing your modules into a provate namespace can protect against name collision. For instance, you could use your initials so that require './library/main.pl'; becomes use RJTD::Main; (See also: perlmodstyle, perlnewmod, perlmod)

    I also find the # center.pl comments a bit jarring, though my recommended alternative would be to document their origin at the beginning of the file like so1:

    use RJTD::Main qw/ get_script_variables panel_start panel_end footer / +; use RJTD::Center qw/ get_general_text page_heading /; #... later get_general_text('musing_cat',1);

    This way, you do not need to document each use of the function since you know that the list of imported functions is always at the top of the file.

    1 When creating your modules use @EXPORT_OK rather than @EXPORT; See Exporter.

    Update: Split EXPORT vs EXPORT_OK into footnote so that things makes sense.

    Good Day,
        Dean

Re^2: How's My Style Now?
by Spenser (Friar) on Feb 08, 2010 at 14:46 UTC
    This is a very cool idea. Using modules would lift me further out of the amateur ranks. It will make maintaining code easier. Plus, it sounds like a fun idea.

    -Spenser

    That's Spenser, with an "s" like the detective.

      Well, it took three long and intensive days once I started, but I converted all of libraries to modules and changed all of my programs which used the libraries to use the new modules. The code is much better now. Next I will have to do the same for my other web sites.

      As an update on where I am now as a coder, I think a couple of years ago I would not have been able to have done this in just three days--it would have taken me at least three weeks, maybe months. I would have tried, gotten confused, stopped, and started again several times before working it out. When I made the previous post on this topic (A Matter of Style in CGI) several years ago, I would not have been able to have changed my libraries and all over to modules. It would have been beyond my comprehension. So, thanks especially for this suggestion. It has helped me to test my skills doing something in Perl that I had never tried to do before, or even thought of doing.

      -Spenser

      That's Spenser, with an "s" like the detective.