Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Your own bag-o-tricks

by vek (Prior)
on May 06, 2002 at 05:34 UTC ( [id://164232]=perlmeditation: print w/replies, xml ) Need Help??

I was just poking around in my home directory and came across something that I wanted to share as I'm sure you've stumbled across the same thing (or something similar).

In the course of writing a program I often find myself opening up another terminal window and hacking a quick foo.pl to test out a particular regex or function. Pretty soon I've got foo.pl, foo1.pl, foo2.pl, bar.pl, bar1.pl so I start using more descriptive names. Such gems as parse.pl, loop.pl, socket_stub.pl, bless_hash.pl start to appear. Pretty soon I've got loads of these mini programs laying around.

I like to get into the habit of saving these snippets of code in my Perl 'bag-o-tricks' directory. I find myself going back into this directory more often than not to hack on existing snippets when coding a big program.

Do you find yourself doing the same kind of thing??

-- vek --

Replies are listed 'Best First'.
Re: Your own bag-o-tricks
by grinder (Bishop) on May 06, 2002 at 12:23 UTC
    This is my setup exactly, as noted here. Sometimes when I manage to polish up a test fragment into something reasonable I upload it to Snippets. I have already referred twice to a couple of my own when working on foreign systems.

    It's nice to know that where ever I am, I can always log into Perl Monks and fetch a couple of code fragments to get me throught the night. Especially as I have bag o' tricks directories scattered all over the place. Perl Monks makes a nice repository.


    print@_{sort keys %_},$/if%_=split//,'= & *a?b:e\f/h^h!j+n,o@o;r$s-t%t#u'
Re: Your own bag-o-tricks
by weini (Friar) on May 06, 2002 at 11:41 UTC
    How do you know it? My homedir looks the same. That's why I had to laugh while reading your node ... you are so right!
    I use to write relatively small scripts for easy tasks and I keep copying stuff together from different scripts.

    And I like your idea of grouping useful things together and saving them in a 'bag-o-tricks' directory.

    Thanks for your input!

    weini

Re: Your own bag-o-tricks
by particle (Vicar) on May 06, 2002 at 13:45 UTC
    there's a little structure to my local snippets repository. i have one directory per language (perl, c, ksh, etc,) and name the scripts after their main function (eg. t-find.pl, t-format.pl, t-hash.pl, t-priorityq.pl, etc.) often, i'll leave a little comment in the code to let me know where i found this bit-o-wisdom (eg. # perlmonks: 164233 tachyon.)

    it's proven extremely useful.

    ~Particle *accelerates*

Your own bag-o-tricks - and one further
by Rex(Wrecks) (Curate) on May 06, 2002 at 16:23 UTC
    I do the same, with one extra step. I have a "sandbox" directory, and another directory inside it called (for lack of a better name, and for legacy reasons :) "goodstuff".

    When I have used a snippet more than 3 times I take the time to make it into a bullet-proof, well documented, subroutine and move it to "goodstuff". Eventually I would like to start grouping them into ones I use together often and package them into modules, but I only have so much time :).

    The other directory in my sandbox is called "test". It contains a very generic network client that attaches to any port or protocol, a few text files with strings that have broken my parsing in the past, and other little dev tools I use to avoid "Making The Same Mistake Twice", or just as little test programs while developing larger things. I find this dir invaluable, having a network client, text files to test parsing, and those types of thing always around so I don't have to rewrite them every time I start writing a server or daemon or even little log parsers, is just a huge time saver.

    Oh and ++ on this node, it might be a given for many, but for any newbies this node will be gold :)

    "Nothing is sure but death and taxes" I say combine the two and its death to all taxes!
Re: Your own bag-o-tricks
by BrotherAde (Pilgrim) on May 06, 2002 at 13:33 UTC

    I've got a whole directory called "Playground". That's where I usuallay start writing any project file, until it matures enough to merit it's own directory. Occasionally, I dump the whole playground into CVS, so I'm sure to keep the bits I'm changing to try out new things. At last count, there's around 150 files in there... should sort them out sometimes...

Re: Your own bag-o-tricks
by mrbbking (Hermit) on May 06, 2002 at 15:02 UTC
    I like your idea of using descriptive names. I have 'temp.pl' in pretty much every directory on all of the computers I use.

    I've been considering going through them for useful snippets and making a 'bag-o-tricks' module for myself. Seems like it would be a good way to work on module-writing skills.

Re: Your own bag-o-tricks
by shadox (Priest) on May 07, 2002 at 04:10 UTC
    Yes i do, ;)
    I usually start with a.pl ,b.pl, then i find the solution i was looking for and i let these little snippets away, and then after some time i start again with a.pl so it already exists and i find myself looking at my last mini program, and thats when i rename it to something more "descriptive", sometimes i just move them to my "tricks" directory with its original name, ( a.pl b.pl ... ) and when i need something and i do a cd tricks i know my answer will be there somewhere. ___________________________________________
    Optimus magister, bonus liber

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://164232]
Approved by grep
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-03-29 09:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found