I am doing the configuration file using Config::Simple
The configuration file i.e. new.conf
[Dialer External]
pass=pass2
user=user2
[Dialer Onboard]
pass=pass1
user=user1
[Dialer Onboard1]
pass=pass1
user=user1
[Dialer Onboard2]
pass=pass1
user=user1
I am reading the configuration file and here is my code
#!/usr/bin/perl
use Config::Simple;
use Data::Dumper;
$cfg = new Config::Simple(syntax => 'ini');
$cfg->read('new.conf');
$cfg = Config::Simple->import_from('new.conf', \%Config);
my @arr = ( keys %Config );
print "@arr";
The hash reference i.e.%Config i am assigning to the array @arrthe output would be
Dialer Onboard1.pass
Dialer Onboard.pass
Dialer Onboard.user
Dialer Onboard2.pass
Dialer Onboard2.user
Dialer External.user
Dialer External.pass
Dialer Onboard1.user
Till here is correct. Now i want to remove some element and assign it to new array that should be something like this
Dialer Onboard1
Dialer Onboard
Dialer Onboard
Dialer Onboard2
Dialer Onboard2
Dialer External
Dialer External
Dialer Onboard1
so that after the dot (.) i don't want any data. For this i am trying to use the grep function.Here is my code for that
@arr = grep { !/./ } @arr;
my @result;
for (@arr) {
if (/./) {
push @result, $_;
}
}
But this is not working for me or it may be wrong approach. I am not able to identify where i am going wrong. And finally i want to remove the duplicate keys from that and that gives me output something like this.
Dialer External
Dialer Onboard
Dialer Onboard1
Dialer Onboard2
Please somebody help me and suggest me how to achieve this.Thanks in advance.