to assign string STR2 to $STR1, however, you are absolutely right that a hash can accomplish what you want, and is in fact a much better way to do it than assigning random variables, especially since it prevents you from overwriting your own program variables :)${'STR1'} = 'STR2';
very simple. you can also check for values by doing something likemy %info; for(@file) { next if /^#/; skip line if it starts with a hash chomp; # remove \n Update ACK! forgot this! Doh! my($name,$val) = split '=', $_, 2; #split line into two # values, on an = sign next unless $val; # make sure you got something $info{$name} = $val; } print "$info{OFFICE} - $info{NAME}\n";
and you can get a list of all your info variables by doingif(exists $info{OFFICE}) { print "Ofiice: $info{OFFICE}\n"; }
try it, and use this to see the results...@keys = keys %info;
That will print a sorted list of all your keys with their values Update forgot to chomp... fixed it... oopsfor(sort keys %info) { print "$_: $info{$_}\n"; }
In reply to Re: Reading from an INI file
by suaveant
in thread Reading from an INI file
by MrCromeDome
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |