A common Ruby idiom involves creating all the classes and methods necessary for a given program and for other programs that might want to use them as in a library call, then in its own little section write the code that makes use of those classes and methods, creating something that works equally well as either a library or a stand-alone script. Thus, for a program that needs nothing but what's in this script/library you just execute the file as a stand-alone program. For a program that also needs other stuff, you can call the script/library as a library, ignore the program logic for running it as its own program, and just make use of the classes and methods in the file.
This is, in Ruby, accomplished by wrapping your stand-alone program logic in a conditional like so:
if __FILE__ == $0
# do stuff
If my first paragraph didn't make any sense to the reader, I hope the example sets things straight. Anyway, I know there's a $0 in Perl that does the same thing as $0 in Ruby, but I'm not able to find an equivalent for __FILE__ anywhere. Does such a thing exist, as such? If not -- what would be the Perl equivalent idiom?
|print substr("Just another Perl hacker", 0, -2);||- apotheon
CopyWrite Chad Perrin
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||