|
Posted by Mr_Noob on February 28, 2008, 1:20 pm
Please log in for more thread options >
>
>
> > Hi all,
>
> > here is a sample of my file :
>
> > ## blah blah
> > [client1]
> > remote=3D192.168.1.2
> > ### some comments here
> > ### blah blah
> > [client2]
> > remote=3D192.168.1.5
> > passive=3Dtrue
> > ###blablah
> > [client3]
> > remote=3D192.168.1.8
> > [client4]
> > remote=3D192.168.1.15
> > passive=3Dtrue
> > ###
> > ####
> > ####
>
> > I am trying to write a perl script that would exclude all comments
> > from the above file and then generate an associative array, and output
> > the following result :
>
> > client1;192.168.1.1
> > client2;192.168.1.5;true
> > client3;192.168.1.8
> > client4;192.168.1.15;true
> > ...
>
> > thanks in advance for ur help...
>
> > br
>
> Here is some pseudocode:
>
> my %hash
> open INFILE, <file.csv
>
> while <INFILE>
> next if $_ =3D~ /#/ #skip comments
> if $_ =3D~ /[/ #create hash element
> create hash element like $hash
> if $hash
> ($key, $value) =3D split on /=3D/ #create vars
> create hashref like $hash =3D $value
>
> close INFILE
>
> foreach my $client (sort keys %hash)
> foreach my $key (sort keys %})
> print $hash - $hash
>
> exit
Thank you for these answers. The problem is that what's inside the
brackets won't always start with the "client"...It can be any string..
I'll also have a look on Config::INI, Config::Simple, Config::Tiny..
|