The file that I'm reading in contains two columns. One for OS and one for Version.
The problem is that sometimes in the Version column, there are multiple versions for the same OS (like 12.4-13.1). What I've done so far is parse the original version out so that it replaces the original with a string like "12.4,12.5,12.6,12.7,12.8...".
Now since I have that string created and the new value is held in the array, is there a way to parse out the new string so that each element is looked at separately, and then place it back into the original array in their own slot instead of all together in one string?
I have tried something similar to this but it's not working as I thought it would. I do a push to my main array before I execute the following code.
thanks for any help.
if (($os=~/CISCO/) && ($ver = "11.14,11.15,11.16,11.17,11.18,11.19,11.20,11.30,11.40,11.50,11.60,11.70,11.80,11.90,12.0.0,12.0.1,12.0.2")){
my @temp_ver = ("11.14","11.15","11.16","11.17","11.18","11.19","11.20","11.30","11.40","11.50","11.60","11.70","11.80","11.90","12.0.0","12.0.1","12.0.2");
my $temp_ver;
$os = "CISCO";
foreach $temp_ver(@temp_ver) {
print"$temp_ver\n";
push @descarray,[$os,$ver];
}
}
this compiles:
----inputfile name=a---
cisco¦10.2-13.4
red hat¦5.2-6.4
suse¦9.8
knoppix¦7-9
----script---
#!/usr/bin/perl -w@in = `cat a`;
foreach $_ (@in){
my ($os,$ver) = ($1,$2) if m@(.*?)\¦(.*)@;
$map{$1} = subversions($2);
}foreach $os (sort keys %map){
print join("\n", map {"$os => $_ "} sort{ $a<=>$b} keys %{$map{$os}}),"\n";
}# create a map of versions
sub subversions {
my $ver = shift ¦¦ '';
my $this = {}; # map of these versions
if( $ver =~ m@(\d+)\.(\d)-(\d+)\.(\d)@ ) {
%$this = map { $_/10 => 1 } ("$1$2".. "$3$4");
}
elsif( $ver =~ m@(\d+)\-(\d+)@) {
$this = { map { $_ => 1 } ( $1..$2) };
}
elsif( $ver=~ m@([\d\.]+)$@ ){
$$this{$1} =1;
}
return $this;
}
-------/script-------
&& ($ver = "11.14,11.15,11.16,11.17,11.18,11.19,11.20,11.30,11.40,11.50,11.60,11.70,11.80,11.90,12.0.0,12.0.1,12.0.2") You're assigning a value to $ver here, which is probably not what you wanted. (Use
eq to compare string equality.) Would this help?
@temp_ver = split(/\,/, $ver);
Still, if I understand, the main crux of the problem seems to be replacing something like "12.1-4" with "12.1","12.2","12.3","12.4." That might look something like this:
if (/(\d+)\.(\d+)\-(\d+)/) {
my ($var1, $var2, $var3) = ($1, $2, $3);
foreach ($var2..$var3) {
push (@array, "$var1.$_");
}
}