如果我的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)
請教Perl高手
所有跟帖:
•
這樣試試
-ohlalala-
♀
(187 bytes)
()
09/23/2006 postreply
20:39:32
•
回複:請教Perl高手
-chadjapan-
♂
(69 bytes)
()
09/23/2006 postreply
21:22:59
•
回複:請教Perl高手
-加州勞模-
♂
(102 bytes)
()
09/24/2006 postreply
10:28:19
•
再請教加州勞模:實驗的時候還好好的
-cutecat123-
♀
(115 bytes)
()
09/24/2006 postreply
11:42:57
•
具體問題具體分析
-加州勞模-
♂
(253 bytes)
()
09/24/2006 postreply
12:11:56
•
看來這種方法又行不通了
-cutecat123-
♀
(177 bytes)
()
09/24/2006 postreply
12:31:23
•
感謝三位好心高手的指教
-cutecat123-
♀
(113 bytes)
()
09/24/2006 postreply
11:07:11
•
我終於找到了用hash的方法。 再次感謝上麵大俠們的援助!
-cutecat123-
♀
(0 bytes)
()
09/24/2006 postreply
15:38:34
•
用什麽perl,看我一句話搞定!
-bigcat1969-
♂
(92 bytes)
()
09/24/2006 postreply
20:14:49
•
你的用法很吸引我
-cutecat123-
♀
(383 bytes)
()
09/24/2006 postreply
21:57:07
•
oFile.txt是指源文件名(list),nFile.txt是輸出文件名
-bigcat1969-
♂
(82 bytes)
()
09/24/2006 postreply
23:04:44
•
抱歉、抱歉,我好像誤會了你的要求。
-bigcat1969-
♂
(98 bytes)
()
09/24/2006 postreply
23:13:59
•
是的, 你誤會了我的要求。 不過不要緊
-cutecat123-
♀
(116 bytes)
()
09/25/2006 postreply
00:40:07