Hi,
I am working on a perl script that needs to read in an entire text file and print out a certain section based on the input
Part of the text file is as follows--
Port 119 NNTP * Microsoft Ports-Microsoft Exchange supports a News server running at + this port. * RFC977 * RFC1036 #------------------------------------------- Port 120 CFDP (UDP) Coherent File Distribution Protocol (CFDP) * RFC1235 #------------------------------------------- Port 123 NTP (UDP) NTP (Network Time Protocol) * RFC2030 * RFC1129 #--------------------------------------------
I need the script to read in and search the text file for a line "Port $port" where $port is the port number and then print out everyline until the "#-----" line.

Currently I have the following which searches the text file and finds the line "Port $port"... But where do I go from there?

sub port_definition { my $port = @_[0]; open(FILE,"ipac_port_defs") || die_nice("Can not open file \"ipac_p +ort_defs\" for reading"); @port_file = <FILE>; close(FILE); foreach $line(@port_file){ if ($line =~ /^Port\s$port/){ $template{port_def} = $line; } } print "Content-type: text/html\n\n"; # Print headers parse("tpl/port_def"); }

If someone could just point me in the right direction.
Thanks,
Shawn

In reply to Help Matching Sections of a file by smaida

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.