This way I can read all the values and then process accordingly$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; }
In reply to Re: Reading a Properties file
by mantra2006
in thread Reading a Properties file
by mantra2006
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |