Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Answer: Read file and remove whitespace

by hdp (Beadle)
on May 01, 2001 at 09:36 UTC ( [id://76881] : note . print w/replies, xml ) Need Help??


in reply to Read file and remove whitespace
in thread Answer: Read file and remove whitespace

while ($line = <>) { my ($k, $v) = split /\s*=\s*/, $line, 2; $values{$k} = $v; }
Your code got a little mangled in the HTML (use <code> tags next time).

I'm using split because what's before and after the = (and any surrounding whitespace) is irrelevant to the pattern -- what you really want to look for is that delimiter. split is natural for this job.

hdp.