Hi,
I am working on a function that would simple store value assignments
statement into an array. The statement is stored in a text file. The
contains of the file would  be

-----------
var word1 one,two,three
var word2 four,five,six
-----------

So I write a function that would read the file and return the variable
and the value in an associate array format. The value of the array at
the end should be

$conf['word1']="one,two,three";
$conf['word2']="four,five,six";

sub get_conf {
    my $local_file = $_[0];
    my @local_conf;
 
    if (open (INFILE, "$local_file")) {
        while (<INFILE>) {
            my $line = $_;

# if line is not a comment
            if ($line !~ /^#|^\s/) { 
                my @conf_fields=split(/\s+/,$line);
                if ( $conf_fields[0] eq "var" ) {
                            $local_conf[$conf_fields[1]] = $conf_fields[2];
                        }
            }
        }
        close (INFILE);

print "A. $local_conf{'word1'} \n";
print "B. $local_conf{'word2'} \n";
        return (@local_conf);
    } else {
        print "$0: file $local_file not found \n";
    }
}

However the print statement at the very end of the function would only print 
"A. four,five,six"
"B. four,five,six"

Where did I do wrong here? Thanks.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to