G'day dwslovedh,

Welcome to the monastery.

I read your post which looked like this:

I came up with a solution and clicked on the "Comment on" link to post it. I then found your posting had completely changed to this:

Please do not do this. If you want to cancel something you've posted, put <strike>...</strike> tags around the whole block of markup; add replacement text if that's appropriate; then add an Update: section which explains the changes you've made.

Here's my solution to your original problem:

#!/usr/bin/env perl use strict; use warnings; my $sep = '=' x 60 . "\n"; (my $dh_file = $0) =~ s/pl$/dat/; open_dh($dh_file); while (1) { print 'Get next DH record (y/n): '; my $reply = <>; if ($reply =~ /^y/i) { print "Next DH record:\n"; my $dh_record = read_dh(); print "$sep$dh_record\n$sep"; if (eof_dh()) { print "No more DH records!\n"; last; } } else { print "Stopped reading DH records.\n"; last; } } close_dh(); { my $dh_fh; sub open_dh { my $dh_file = shift; open $dh_fh, '<', $dh_file or die "Can't read $dh_file: $!"; my $discard = read_dh(); return; } sub read_dh { local $/ = 'DH: '; my $dh_trim_re = qr{\A \s* (.*?) \s* (?: DH: \s )? \z}msx; my $dh_record = <$dh_fh>; $dh_record =~ s/$dh_trim_re/$1/; return $dh_record; } sub close_dh { close $dh_fh; return; } sub eof_dh { return eof $dh_fh; } }

Here's a sample run:

$ pm_get_multi_rec.pl Get next DH record (y/n): y Next DH record: ============================================================ mm struct{ int a; char b; m1 struct { int c; int d; }; m2 struct { int e; int f; }; } 2 dfdkk df dd } 1 LOCAL_PARAM: ssi_struct { ref = 0; header = { req = 0xa; }; } ============================================================ Get next DH record (y/n): y Next DH record: ============================================================ mm struct{ int a; char b; m1 struct { int c; int d; }; } ============================================================ No more DH records!

-- Ken


In reply to Re: I want to write a function, you call it ,it will return one matched record each time! by kcott
in thread I want to write a function, you call it ,it will return one matched record each time! by dwslovedh

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, 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:
    & &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.