On Mar 10, Karsten Borgwaldt said:
>key=value
>key2=value2
>....
>
>This is the sourcecode:
I can assure you it isn't; your code assigns to $1, $2, and $3 -- you
can't do that.
>open(file, "< foo.bar");
If you had warnings on, you'd be told that filehandles should be written
in uppercase for safety.
open FILE, "< foo.bar";
>@myArray = <file>;
>close(file);
>foreach (@myArray) {($1, $2, $3) = split /=/; $list{"$1"}=$3;}
There's no need to read the file into an array and then loop over the
array. Why not do:
while (<FILE>) {
chomp; # remove the newline;
my ($field, $value) = split /=/;
$data{$field} = $value;
}
The reason your code breaks is because you are misunderstanding
split(); it does NOT return what the regex matched.
split /=/, "a=b"
does not return ("a", "=", "b"). It returns ("a", "b").
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
[ I'm looking for programming work. If you like my work, let me know. ]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]