Here's more of a general question which I would like your comments on. I asked the original question for the following reason: I am writing a script that parses #NEXUS files, which are text files that contain data and processing instructions for phylogenetic inference. The data is marked up using various tokens. For example, there might be one or more sections that define species names. These would be of the form:
begin taxa;
[...stuff goes here..]
end;
There might also be one or more sections that deal with DNA sequence data, which are like this:
begin characters;
[...stuff here...]
end;
There's a bunch of other possible blocks, but you get the idea.
The reason why I asked the question is that I thought it would be clever to have it such that, while the script is doing its while(<>) thing, it would call the appropriate sub to process that section simply by virtue of stumbling across the
begin (this would be the signal to start calling the sub); token. For instance, it finds
begin taxa;, there would be a
&$var() where
$var now contains the value "taxa" so the
sub taxa { [...] } starts doing its thing.
I realize now that the script would fail if something that looks like a token that should reference a sub is found, but there is no sub for it, i.e.
begin (something I haven't thought of);. I could then of course work around this by including a bunch of ifs, but the dispatch table looks more elegant so I'll go with that. Thank you those that suggested that (well, and everyone else for replying also - this place is wonderful).
Now comes my question: can something else bad happen, along the lines of
$$var = 'something'; when, inadvertently,
$var takes on a value such as *, or ! but then in the case of subs? Let's say the #NEXUS file contains the string
begin die;. I guess that would be problematic, right?
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.