grim has asked for the wisdom of the Perl Monks concerning the following question:
# config.txt name = foo name2 = foo2 ...
# config.pl open(FILEHANDLE, "config.txt"); $values = {}; while ($line = <FILEHANDLE>) { $line =~ /^([^=]+)=(.*)/; $values{$1} = $2; }
but in the config file there might be whitespace before and after the '='. How would I get rid of it? I know it must be done with a regular expression. I got this reg exp. from a tutorial on perl.com and I don't completely understand how it works so if you could please explain your solution that would be great as I am really trying to learn.
Thanks
Edited 2001-05-01 by mirod: added <code> tags
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Read file and remove whitespace
by jeroenes (Priest) on May 01, 2001 at 09:56 UTC | |
|
Answer: Read file and remove whitespace
by hdp (Beadle) on May 01, 2001 at 09:36 UTC | |
|
Re: Read file and remove whitespace
by grim (Initiate) on May 01, 2001 at 15:21 UTC | |
|
Re: Read file and remove whitespace
by Sifmole (Chaplain) on May 01, 2001 at 17:19 UTC | |
by grim (Initiate) on May 02, 2001 at 06:14 UTC | |
|
Re: Read file and remove whitespace
by diarmuid (Beadle) on May 01, 2001 at 17:25 UTC |