If this is a repetitive task that you're performing on each of your $mcc, $mnc, $lac, etc. variables, then the easiest way to eliminate the repetitive code is to put the values into an array or hash and use a loop to iterate over all of them. I'd use a hash in your case. For example:
my @fieldnames = qw/cellsiteID sectID mcc mnc lac ci bscid bts bearin
+g mscID lat long tilt agl/;
my %hash; # you'll want a better name :-)
while (<OSS>) {
@hash{@fieldnames} = split /,/;
my %new = %hash; # new values go here
my $key = join "_", @hash{'cellsiteID','sectID'};
next unless exists $h_ssect{$key};
my @scoutSA = split(/,/,$h_ssect{$key});
for my $f (@fields) {
if ($hash{$f} ne $scoutSA[$ocfg{'oss2.primpos'}]) {
$new{$f} = $hash{$f};
push(@{$chged{$key}}, $hash{$f},$scoutSA[$ocfg{'oss2.primpos'}
+] );
}
# ...
}
I'm not sure how $scoutSA[$ocfg{'oss2.primpos'}] varies from $mcc to $mnc to the next variable and so on, so you'd need to incorporate a mapping in there for that too.
Some general observations about your code:
- I think it's weird that you're pushing the two "NULL" values when you're not making a change.
- if you're going to use the expression $cellsiteID."_".$sectID many many times, you might just want to stick that in a variable of its own so that you don't inadvertently screw up.
- you probably don't want to use a pattern match when comparing the values in case there are characters that are special to the regular expression engine. Just use straight equality operators. Since you say some are strings and some are numbers, keep a hash that tells you which is which so that your program knows which equality test to perform.
- If the rest of your loop consists entirely of the body of that if statement, you may want to eliminate a little of the stairstep effect by using next unless exists $h_ssect{$key};
I've made these assumptions and included them in my example above. If I'm way off base, let me know.
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.