#!/usr/bin/perl -w use strict; my $file = shift || die "SYNOPSIS: $0 datafile\n"; open( IN, $file ); my @in = ; close IN; # # The raw data is almost already in perl format. # my @out; foreach( @in ) { last if /: ENDINTERROG/; push @out, "};\n\nsub ports\n{\n" if /:/; next if /:/; s/-\s*/-/g; # remove whitespace after minus sign s/(\d+)\%/0.$1/g; # change n% to 0.n # finally, turn it into a hash reference s/^\s*(\d+) (.*)$/ \'$1\' => [ qw ( $2 ) ],/; push @out, $_; } open OUT, ">$file.pm"; print OUT<