I have a flat file that is large enough to fit into memory and all i want to do is read the file line by line and if the line contains a specific value 'read_community XXXXX' print 'read_community newstring'. Here is where I am at:
open NCNODE, "/path/nervecenter.node"
or die "Error opening Nerve Center Node file ($!)";
foreach my $variable (<NCNODE>) {
chomp;
print STDOUT $variable;
}
close NCNODE;
I know that i need to place an if statement where i have the print line. But, i guess i am having an issue with the syntax. I was thinking that it would be something like:
if ($variable eq 'read_community'){
print;
}
But, it does not seem to be correct. Below is a sample of the file.
begin node
name Router
on_off on
group Frame_Relay
suppress no
auto_delete yes
read_community readstring
write_community readstring
address 10.0.0.0
port 161
snmp_version 1
engineid 0
auth_protocol 0
is_key_ok 1
error_status 0
security_level 0
end node
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.