For your first example, this type of command line argument parsing can be carried out more simply with the
-s switch to the Perl executable - This argument enables rudimentary switch parsing on the command line after the script name but before any filename arguments (or before a --). Any switch found is removed from
@ARGV and a variable with a corresponding name is set.
For example, the following code will print bar! if the command line switch -foo is passed to the script:
#!/usr/bin/perl -s
print "bar!\n" if ($foo);
This behaviour is documented in perlrun - For a truly evil use of this behaviour (and Perl in general) have a look at theDamian's selfGOL obfuscation :-)
perl -e 'print+unpack("N",pack("B32","00000000000000000000000111011111")),"\n"'
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:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.