Hey guys,
I have started to learn perl recently because of a position I took. They want me to master perl and I've been reading books and practicing myself.
Basically I,m having my perl script run through a text pad and give the output in a special way
set deviceconfig system snmp-setting snmp-system location "VA"
set deviceconfig system snmp-setting snmp-system contact US
set deviceconfig system snmp-setting snmp-system send-event-specific-traps yes
set deviceconfig system snmp-setting access-setting version ll1 snmp-community-string trap
so far I have
open (NAMES_FILE, "<input.txt") or die "Failed to read file : $! ";
my @not_sorted = <NAMES_FILE>; # read entire file in the array
print @not_sorted;
close (NAMES_FILE);
so I am putting all the file into an array, but what I want to do is, I want it to paste everything before a bracket open and the statement after it. I would really appreciate some help.
You may either do this using vanilla Perl or make your life very simple by using a configuration file parser such as Config::Scoped. See CPAN for its documentation. Also check out other config parsers (although this one will do your job).
Since I am accessing the forum through my mobile, can't help you much. Sorry.
Without using any config parsers and with certain assumptions about your input data (based on the sample provided):
#!/usr/bin/perl
use strict;
use warnings;
open my($in_file), '<', '/path/to/inputfile'
or die "Could not open file: $!\n";
my @params = qw(set);
while(<$in_file>) {
next if (/^\s+$|^\s*#/);
if(/^\s*}\s*$/) { pop @params; next}
my @tokens = split;
if ($tokens[1] =~ /{/) { push @params, $tokens[0]; next }
s/^[ \t]*|;.*$//g;
print "@params $_";
}
close $in_file;