Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Well, if you've got a particularly well constrained data set, then you might be able to achieve what you want without *too* much trouble. However, your example of using a string containing a semi-colon only touches on the complexity of the problem --- here's another:

my $x = do{ print "here's an embedded statement\n"; 42; };

And we can imagine all sorts of complications using other quote-like mechanisms like s//statement;statement;/e or s;;;ge ... But even if you can grok all the combinations of quote-like operators and embedded multi-statement terms, you still have a problem. As merlyn so aptly points out in this node, from which I'll extract (and modify) just one little tidbit:

$x = sin / 25 ; # /; die "Bang! I'm dead!"; $y = time / 25 ; # /; die "I'm only pretending!";

Where does the first statement end in each of these two lines? It isn't just that you have to ignore semi-colons inside of a match operation, you have to know whether you are even in a match operation at all. Thus, while the question as you pose it may *seem* like something far less complex than actually "parsing Perl" (I just want to recognize one leading, semi-colon terminated, arbitrary statement) it really isn't at all.

And we've competely ignored other things such as many statements without terminating semi-colons(in the same vein as Beatnik mentions):

while(<>){ if ($. == 1){ print "Now processing $ARGV ...\n" } print if /something/ .. /something else/ } continue { close ARGV if eof }

Which of course is rather contrived ... but still something to consider depending on what you are *really* trying to accomplish (although you did explicitly mention terminating semi-colons, so perhaps this isn't an issue for you).

On the other hand, I seem to recall that Simon Cozens (I think) was working on a Perl parser in Perl --- but I have no idea how far that went or what became of it.


In reply to Re: Matching first Perl statement. by danger
in thread Matching first Perl statement. by vladb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2024-04-16 05:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found