[問題] I/O 的問題

看板Perl作者 (yingwan)時間16年前 (2008/10/08 08:24), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/2 (看更多)
現在在練習寫一個情境,要使用者輸入id,密碼,email 然後把這寫資料寫入檔案裡 如果檔案裡已經有同樣的id名稱,要使用者重新輸入那些資料 一直遇到的問題是,我的程式一直無法偵測重覆的id 希望有好心人幫我看看我哪裡寫錯了,感激不盡 #!/usr/bin/perl #----------------------------------------------------- #Prompts the user for the userID, password and email #Reprompt if userID already exist #otherwise, append the input to the file #------------------------------------------------------ $file="hw.out"; open(IN,$file) || die "can't read $file"; @all = <IN> ; close(IN); chomp @all; %all= (); foreach (@all) { ($id,$psw, $email) = split(/,/,$_); $all{$id} = $pw; print "Please enter your user ID:"; chomp ($id=<STDIN>); print "Please enter your password:"; chomp ($psw=<STDIN>); print "Please enter your email address:"; chomp ($email=<STDIN>); if (exists ($all{$id})) { print "Please enter your user ID:"; chomp ($id=<STDIN>); print "Please enter your password:"; chomp ($psw=<STDIN>); print "Please enter your email address:"; chomp ($email=<STDIN>); } else { open (IN, ">>$file") || die "can't write to $file"; print IN "$id, $psw, $email\n"; last; }} 再次感謝好心人指教 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 149.159.132.73
文章代碼(AID): #18w_tI_U (Perl)
討論串 (同標題文章)
以下文章回應了本文
完整討論串 (本文為第 1 之 2 篇):
文章代碼(AID): #18w_tI_U (Perl)