Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

OK, here's yet another way of doing it. This uses a state machine (or at least that's what I think is what is meant by a state machine.)

I've tried to take it a bit further to show that this approach can be quite flexible - I've got it to pull out the YACCCOMPILE lines as well to show that you can look for more than one thing and have also added dummy YACCCOMPILE lines to show that you can actually pick up further lines as they occur.

You can, of course, get this to look for as many start points as you want. The code could probably be reduced, but attempting to do so would probably detract from the clarity of the example.

Hope this helps!

use strict; use warnings; my $state=0; my ($yacccompile,$sources); while (<DATA>) { if ($state==0) { # Wait until we see SOURCES. if ($_=~/^SOURCES/) { # Move to next state, re-read line # in that next state. $state=1; redo; } # ...or we see YACCCOMPILE elsif ($_=~/^YACCCOMPILE/) { $state=2; redo; } } elsif ($state==1) { # See if we have reached another section: if ($_=~/^[A-Z]/ && $_!~/^SOURCES/ ) { $state=0; redo; } else { # Supress blank lines. next unless $_=~/\w/; # Add the line to what we have so far. $sources.=$_; } } elsif ($state==2) { # See if we have reached another section: if ($_=~/^[A-Z]/ && $_!~/^YACCCOMPILE/ ) { $state=0; redo; } else { # Supress blank lines. next unless $_=~/\w/; # Add the line to what we have so far. $yacccompile.=$_; } } } # Now print it all out with some titles. print "SOURCES\n-------\n\n"; print $sources; print "\n"; print "YACCCOMPILE\n----------\n\n"; print $yacccompile; print "\n"; __DATA__ YACCCOMPILE = $(YACC) $(YFLAGS) $(AM_YFLAGS) LTYACCCOMPILE = $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) + \ --mode=compile $(YACC) $(YFLAGS) $(AM_YFLAGS) YLWRAP = $(top_srcdir)/ylwrap SOURCES = $(libpiuserland_la_SOURCES) $(pilot_addresses_SOURCES) + \ $(pilot_clip_SOURCES) $(pilot_csd_SOURCES) + \ $(pilot_debugsh_SOURCES) $(pilot_dedupe_SOURCES) + \ $(pilot_dlpsh_SOURCES) $(pilot_file_SOURCES) + \ $(pilot_foto_SOURCES) $(pilot_foto_treo600_SOURCES) + \ $(pilot_foto_treo650_SOURCES) $(pilot_getram_SOURCES) + \ $(pilot_getrom_SOURCES) $(pilot_getromtoken_SOURCES) + \ $(pilot_hinotes_SOURCES) $(pilot_install_datebook_SOURCES) + \ $(pilot_install_expenses_SOURCES) + \ $(pilot_install_hinote_SOURCES) $(pilot_install_memo_SOURCES) + \ $(pilot_install_netsync_SOURCES) $(pilot_install_todo_SOURCES) + \ $(pilot_install_todos_SOURCES) $(pilot_install_user_SOURCES) + \ $(pilot_memos_SOURCES) $(pilot_nredir_SOURCES) + \ $(pilot_read_expenses_SOURCES) $(pilot_read_ical_SOURCES) + \ $(pilot_read_notepad_SOURCES) $(pilot_read_palmpix_SOURCES) + \ $(pilot_read_screenshot_SOURCES) $(pilot_read_todos_SOURCES) + \ $(pilot_read_veo_SOURCES) $(pilot_reminders_SOURCES) + \ $(pilot_schlep_SOURCES) $(pilot_wav_SOURCES) + \ $(pilot_xfer_SOURCES) YACCCOMPILE = niddle naddle noo RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive + \ html-recursive info-recursive install-data-recursive + \ install-dvi-recursive install-exec-recursive + \ install-html-recursive install-info-recursive + \ install-pdf-recursive install-ps-recursive install-recursive + \ installcheck-recursive installdirs-recursive pdf-recursive + \ ps-recursive uninstall-recursive YACCCOMPILE = foo bar baz

In reply to Re: Reading "slices" out of a file at known start markers by smiffy
in thread Reading "slices" out of a file at known start markers by hacker

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



  • 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, 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
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (14)
    As of 2018-07-18 11:18 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















      Results (390 votes). Check out past polls.

      Notices?