> Is there a better way of building a hash from a file than
> this?
> 
> ---8<---
>   while (<FILE>){
>      ($mt,$te) = split /;/,<FILE>;            
>     $tt{$mt} = $te;
> }
> ----8<-----
>

If you were desperate something like:

$hash{$key} = $value while (!eof && ($key, $value) = split
/;/, <FILE>); 

might work.  However, it doesn't quite look as easy to
read.  Honestly, you don't really want to shorten what you
are doing - it reads fine.  Here is how I'd do it:

while (<FILE>){
    my ($key, $value) = split ';';
    $hash{$key} = $value;
}

Notice the lack of that <FILE> for split... that would have
the wrong behaviour.  Finally, you CAN do it with a regex:

while (<FILE>) { $hash{$1} = $2 if /^([^;]*);([^;]*)/ }

Jonathan Paton

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to