--- On Tue, 8/5/08, sonika tyagi <[EMAIL PROTECTED]> wrote:
> From: sonika tyagi <[EMAIL PROTECTED]>
> Subject: Re: [ilugd] Perl script errors - parsing config file
> To: [EMAIL PROTECTED], "The Linux-Delhi mailing list"
> <[email protected]>
> Date: Tuesday, August 5, 2008, 6:37 PM
> Hi,
>
> You'll have to make some changes in your script. Those
> have been highlighted
> in blue and red color below.
> It'll run now.
> Cheers
> Sonika
>
> On Wed, Aug 6, 2008 at 7:59 AM, Sudeep Sharma
> <[EMAIL PROTECTED]> wrote:
>
> > Hello All,
> >
> > I have copied this script from this url which solves
> one of my purpose of
> > parsing a config file. Here is the URL
> >
> http://www.motreja.com/ankur/examplesinperl/parsing_config_files.htm
> >
> > Now when I am running the script I am getting these
> errors:
> > Use of uninitialized value in pattern match (m//) at
> config_parser.pl line
> > 26.
> > Use of uninitialized value in split at
> config_parser.pl line 27.
> > Use of uninitialized value in hash element at
> config_parser.pl line 28.
> >
> > Here is the copy of script, may be there is something
> which I am not doing
> > properly. Could someone please help me running this
> script successfully.
> >
> > =================================script
> begins============================
> > #! perl -w
> >
> > $path_and_filename="data.txt";
>
> %Config=(); #global variable
>
> >
> >
> > # Call the subroutine
> > &parse_config_file ($path_and_filename,
> \%Config);
> >
> > foreach $Config_key (keys %Config) {
> >
> > print "$Config_key =
> $Config{$Config_key}\n";
> >
> > }
> > sub parse_config_file {
> >
> > local ($config_line, $Name, $Value, $Config);
> >
> > ($File, $Config) = @_;
> >
> > if (!open (CONFIG, "$File")) {
> > print "ERROR: Config file not found :
> $File";
> > exit(0);
> > }
> > #while () {
>
> while ($config_line=<CONFIG>) {
>
> >
> > # $config_line=$_;
> > chop ($config_line); # Get rid of the
> trailling \n
> > if ($config_line !~ /^#/) { # Ignore lines
> starting with # and
> > blank lines
> > ($Name, $Value) = split (/=/,
> $config_line); # Split
> > each line into name value pairs
> > $$Config{$Name} = $Value;
> >
> $Name=$Value=""; #reinitialize the
> variables
>
> > # Create a hash of the name value
> pairs
> > }
> > }
> >
>
>
> > close(CONFIG);
> > }
> > =================================script
> ends==============================
Thanks it worked. Appreciate your help.
_______________________________________________
ilugd mailinglist -- [email protected]
http://frodo.hserus.net/mailman/listinfo/ilugd
Archives at: http://news.gmane.org/gmane.user-groups.linux.delhi
http://www.mail-archive.com/[email protected]/