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?