Hi,
I'm trying to parse some log data, and I'm having trouble with my RegEx.
I'm reading an input file as a list:
@lines = (<FILEHANDLE>);
foreach (@lines) {
if (/^\+/) {
# line starts with a "+", take action here
print "$_\n";
}
}
I'm trying to catch lines in the file that begin with "+", and I thought I could escape it with \ to match that pattern, but my diagnostic print call never occurs when it goes through the file. Am I specifying/escaping the + symbol correctly? I know + is used in RegEx frequently... so it's go to be escaped somehow.
Here's my second RegEx problem. I need to read a list of port numbers that are formatted in the same file. Here's some sample data:
o smtp (25/tcp)
o www (80/tcp)
o pop3 (110/tcp)
How can I structure my if statement to catch that format? Each line with a port starts with an "o"... then the service name (www, smtp, etc.). There is always a (, then the port number (1-65535), a /, and then either tcp or udp is specified... and finally a closing ).
if (/^o /) { print "port found"; }
Is that in the right direction? I need to separate the service name (smtp, www, etc.), the port number, and the port protocol into individual variables or into an array. How can this be accomplished easily?
Any help is greatly appreciated... thanks
[x]
I'm trying to parse some log data, and I'm having trouble with my RegEx.
I'm reading an input file as a list:
@lines = (<FILEHANDLE>);
foreach (@lines) {
if (/^\+/) {
# line starts with a "+", take action here
print "$_\n";
}
}
I'm trying to catch lines in the file that begin with "+", and I thought I could escape it with \ to match that pattern, but my diagnostic print call never occurs when it goes through the file. Am I specifying/escaping the + symbol correctly? I know + is used in RegEx frequently... so it's go to be escaped somehow.
Here's my second RegEx problem. I need to read a list of port numbers that are formatted in the same file. Here's some sample data:
o smtp (25/tcp)
o www (80/tcp)
o pop3 (110/tcp)
How can I structure my if statement to catch that format? Each line with a port starts with an "o"... then the service name (www, smtp, etc.). There is always a (, then the port number (1-65535), a /, and then either tcp or udp is specified... and finally a closing ).
if (/^o /) { print "port found"; }
Is that in the right direction? I need to separate the service name (smtp, www, etc.), the port number, and the port protocol into individual variables or into an array. How can this be accomplished easily?
Any help is greatly appreciated... thanks
[x]

