请教Perl高手

如果我的text file这样的:

name=lisa
age=20
location=NewYork


我需要把”=”左边变成 Variable 名字, 右边是它们的Value
我的笨办法打开text file, 用”=”split 每行, 然后

if ($myVar =~ /name)
{
$name =…;
}
elsif ($myVar =~ /age/)
{
$age =…;
}

当 list 太长了后, 这样就非常笨, 长而难看_:$ . 请大侠在这里帮指点一下, 用优化的方法, 自动将”=”左边变成 Variable 名字, 右边是它们的Value.
盼。。。

万分感谢_(f)

所有跟帖: 

这样试试 -ohlalala- 给 ohlalala 发送悄悄话 (187 bytes) () 09/23/2006 postreply 20:39:32

回复:请教Perl高手 -chadjapan- 给 chadjapan 发送悄悄话 (69 bytes) () 09/23/2006 postreply 21:22:59

回复:请教Perl高手 -加州劳模- 给 加州劳模 发送悄悄话 (102 bytes) () 09/24/2006 postreply 10:28:19

再请教加州劳模:实验的时候还好好的 -cutecat123- 给 cutecat123 发送悄悄话 (115 bytes) () 09/24/2006 postreply 11:42:57

具体问题具体分析 -加州劳模- 给 加州劳模 发送悄悄话 (253 bytes) () 09/24/2006 postreply 12:11:56

看来这种方法又行不通了 -cutecat123- 给 cutecat123 发送悄悄话 (177 bytes) () 09/24/2006 postreply 12:31:23

感谢三位好心高手的指教 -cutecat123- 给 cutecat123 发送悄悄话 (113 bytes) () 09/24/2006 postreply 11:07:11

我终于找到了用hash的方法。 再次感谢上面大侠们的援助! -cutecat123- 给 cutecat123 发送悄悄话 (0 bytes) () 09/24/2006 postreply 15:38:34

用什么perl,看我一句话搞定! -bigcat1969- 给 bigcat1969 发送悄悄话 (92 bytes) () 09/24/2006 postreply 20:14:49

你的用法很吸引我 -cutecat123- 给 cutecat123 发送悄悄话 (383 bytes) () 09/24/2006 postreply 21:57:07

oFile.txt是指源文件名(list),nFile.txt是输出文件名 -bigcat1969- 给 bigcat1969 发送悄悄话 (82 bytes) () 09/24/2006 postreply 23:04:44

抱歉、抱歉,我好像误会了你的要求。 -bigcat1969- 给 bigcat1969 发送悄悄话 (98 bytes) () 09/24/2006 postreply 23:13:59

是的, 你误会了我的要求。 不过不要紧 -cutecat123- 给 cutecat123 发送悄悄话 (116 bytes) () 09/25/2006 postreply 00:40:07

请您先登陆,再发跟帖!