Perl Regex Help -- Reading In Text Files
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_port_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.
Last edited by smaida; 04-04-2004 at 07:13 PM.
|