You already seem to have a firm grasp of regexs. You can read a bit more in perlre, Death to Dot Star! and 7 Stages of Regex Users. Look also at the links in regex tutorial, and of course at YAPE-Regex-Explain-1.01 released!. What you want, is simply an insertion of \s* around the '=' to allow any amount of whitespace to be read in.
... $line =~ /^([^=]+)\s*=\s*(.*)/;
Furthermore, I would add a chomp $line; at the beginning of your while loop to remove newlines from your hash. Other issues: You don't check for the occurrence of a comment-line; If you only can have one '=', you'd better stick with split. That all results in:
I used $_, it gets automagically assinged to by the while. Removes a bit of the code's complexity.while( <> ){ next if /^#/; #check for comment next unless /=/; #check if = present chomp; #remove newline split /\s*=\s*/, $_, 2; #split line to @_ $values{ $_[0] } = $_[1]; #assign to hash }
Cheers,
Jeroen
"We are not alone"(FZ)
In reply to Re: Read file and remove whitespace
by jeroenes
in thread Read file and remove whitespace
by grim
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |