in reply to Reading a Properties file

Hello Monks
I didn't permissons to download CPAN modules..so I came up with the following code
suggest me if anything is wrong
$config = "C:\\Testing\\file.ini"; # check if file exists and can be read -r $config || die "$config does not exists or is not readable"; open(IN, $config) || die "Cannot open $config for reading: $!"; sub readFile { my $key = ""; my $value = ""; # initialize rule storage my $source_dir = ""; my $target_dir = ""; my @pattern; while(<IN>) # read a line from line into $_ { $line = $_; if ( /^(\s*|\;.*|\#.*)$/i ) { # empty line or comment } elsif ( ($key, $value) = /^\$([A-Z_]+)\=(.+)/ ) { #significant line: $key=$value $value = evalValue($value); #$key = lc($key); # look for file attributes $source_dir=$value if( $key eq "SOURCE_DIR" ); $target_dir=$value if ( $key eq "TARGET_DIR" ); @pattern=$value if ( $key eq "PATTERN" ); } } } sub evalValue { my $value = $_[0]; my $key = ""; my $result = ""; my $rest = ""; $_ = $value; $rest = $value; while( ($key) = /\$([A-Z_]\w*)/) { $key_val{$key} || die "Undefined key: $key $!"; $result = $result . $` . $key_val{$key}; $_ = $'; $rest = $'; } $result = $result . $rest; return $result; }
This way I can read all the values and then process accordingly

Thanks again for suggestions

Sridhar

Replies are listed 'Best First'.
Re^2: Reading a Properties file
by duff (Parson) on Aug 16, 2006 at 18:52 UTC

    You can't download a module, but you can write your own code? I'm having a hard time with this concept. At the very least you can download the module and include its source code within your program. Or you could install the module in your "disk area" and use it from there. If anyone asks, we'll tell them that you wrote it. :-)