Forum Moderators: coopster & phranque

Message Too Old, No Replies

code library - i'd like to manage my perl code snippets better

what do the pros use to manage their snippets?

         

jeremy goodrich

12:15 am on Jan 30, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm getting to the point in perl that at least half of my 'new tasks' i have exising code I start with, and more and more of it is my own.

I don't document in the code, I don't insert headers with descriptive info, and I don't put comments between the functions so that another programmer would be able to follow along with ease.

I'd like to put my stuff together, in a library of sorts, so I could get at the various functions, utilities, and snippets without too much effort, instead of 'cd'ing' around my box trying to remember what snippet was part of what application which would be where again?

Surely, others have this same problem/issue. How to best get organized? thanks.

Damian

7:04 am on Jan 30, 2002 (gmt 0)

10+ Year Member



Maybe you could write your own package which is part of @INC ?
You could then call your routines from any script.
Ie.you'd start your scripts with "use Jeremy::XMLParser"

Josk

9:46 am on Jan 30, 2002 (gmt 0)

10+ Year Member



alternativly use:

package myPerlUtils

and then in the perl script:

$result = &myPerlUtils::mySub();

as long as myPerlUtils is in the include path then you should be ok

Brett_Tabke

7:56 pm on Jan 30, 2002 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



I use a fairly modern filing system. It is heirarchical in nature and allows me to drill right down to the snippet I want. I can even search through all the files to find what I need. It's a new database called a file system. ;)

To use it, just open your favorite file manager and create a new directory for your database called "perl snippets". Under the "snippets" directory, just create a directory as you need it. When you do that new "download a page" script, just put it in the "www" directory. When you need to find that snippet, just open you filemanager again and perform a search on the directory.

As far as I know, the "file system" method is usable on virutally all computers in use today. ;)

Josk

10:15 am on Jan 31, 2002 (gmt 0)

10+ Year Member



(not sure if this meant as humor)

yes...

but using code libraries allows me to do things like:

$num = &utils::parseWebPage(&utils::urlFetch(&utils::getSerps("foo", "altavista")))

Or...work out the serp page for "foo" in Altavista, get it and count the number of items in it. $num is (with one line of code) equal to the the number of items that are ranked in Altervista for "foo".

Impresses the hell out of managers...

Brett_Tabke

9:30 pm on Jan 31, 2002 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



I probably have 300 scripts and snips I keep in a directory called (slap forehead) "snips". I was trying to point out that we often reinvent the wheel, when the wheel is right in front of us. After all, what is a file system but a great database system?

jeremy goodrich

10:06 pm on Jan 31, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ya, ya, ya...too funny, Brett.

I was just wondering if there was any 'killer application' that I should use, with low learning curve, that would do essentially the same thing...

Now all I need to do is put them all into the same dir, label it 'snips' and call it good, I suppose. Thanks for the suggestion.

>>about the &main::jeremy idea

Good one, but until I get to be a real 'perl h@cker' I don't think I'll try anything like that, would probably take too much time to learn how to do. :) thanks for the idea, though, someday...

Allen

1:06 pm on Feb 20, 2002 (gmt 0)

10+ Year Member



I create 'libraries' of commonly used code. For example, I have one file called template.pl which contains all the code for using templates with my scripts, and another called db.pl which hold all my datbasing routines (add, delete, sort, search)

I've only recently found out the PM's are almost exactly the same as PL's, whwich is why their not PM's. Just habit now.

As a side note, I rarely use the template 'library' now as I tent to use SSI instead - it's easier when you want to use multiple scripts on the same page (eg. a time display (done with SSI), a counter (some of our clients still want them - so we make them pay for their stupidity *g*) and perhaps a links database, oh and a script which shows the recent threads on the forums)

Allen

rogerd

2:46 pm on Feb 21, 2002 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I think it may be overkill for simple code organization, but I use a cheap tool called Personal Knowbase to store bits of knowledge I don't want to forget - I often stick pieces of code in, too. The advantage of this tool is that you can assign keywords to every entry, plus do text searches. It makes retrieving something you stored six months ago easy, even if you forget what you called the file. If you wanted to mix in text information, comments on how you used a script or problems you encountered, etc., this could be a good tool.

Woz

10:34 pm on Feb 21, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



For those using ASP, there is a very nice little Script Library application here [planet-source-code.com].

It needs a little tweaking in the display department and could use a few extra features, but it is a good starting point for building a library that suits your personal needs.

Onya
Woz