Re: [問題] 點點(..)運算子兩問

看板Perl作者 ( )時間10年前 (2013/10/29 02:15), 編輯推噓2(205)
留言7則, 6人參與, 最新討論串5/6 (看更多)
man perlop The right operand is not evaluated while the operator is in the "false" state, and the left operand is not evaluated while the operator is in the "true" state. The precedence is a little lower than || and &&. The value returned is either the empty string for false, or a sequence number (beginning with 1) for true. The sequence number is reset for each range encountered. The final sequence number in a range has the string "E0" appended to it, which doesn't affect its numeric value, but gives you something to search for if you want to exclude the endpoint. You can exclude the beginning point by waiting for the sequence number to be greater than 1. 所以 3..5 每次拿到的值是 '' '' 1 2 3E0 '' '' 3E0 的數值還是 3, 但是可以拿來判斷是不是最後一個 結論: perl 好噁心 ※ 引述《AntaresStar ()》之銘言: : 回到原本的問題 自問自答一下 XD : 改成這樣 : $arr=[0,1,2,3,4,5,6,7]; : while(<DATA>) { : print $arr->[3..5]; : } : __DATA__ : A : B : C : D : E : F : G : 會印出0012300 : 於是可以發現在->[]裡的..確實被當成flip-flop : 而且還可以看到flip-flop為true的時候 實際上值會從1開始一直++ : ※ 引述《CindyLinz (Cindy Wang)》之銘言: : : 就這樣的意思呀~ : : sub processLine { : : if( 3 .. 5 ) { : : print $_; : : } : : } : : while(<>){ : : processLine(); : : } : : processLine 裡面的 3 .. 5 不會隨著進出 processLine 而重置~ : : 用在這邊是方便啦, 只是這種隱藏地永久存在的狀態是比較危險的東西 :Q -- -----BEGIN GEEK CODE BLOCK----- Version: 3.12 GCS/M d-(+) s:+ a- C++$ UL++B+ P++(++++) L+ E--@ W++ N? o? K? w(++) !O M !V PS++(+++) PE++(+++) !Y PGP t+++ !5 !X R !tv b++ DI++ D+ G e+++>++++ h--* r% y+ ------END GEEK CODE BLOCK------ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 128.36.232.45

10/29 10:02, , 1F
竟然真的有寫在說明書上 @@
10/29 10:02, 1F

10/29 11:11, , 2F
推(Y),又長知識了
10/29 11:11, 2F

10/30 22:54, , 3F
推(Y), 也長知識了
10/30 22:54, 3F

10/30 22:59, , 4F
長知識是在說現在才知道 perl 好噁心嗎?
10/30 22:59, 4F

10/31 13:49, , 5F
什麼什麼, 哪邊有講那句嗎? ^_<
10/31 13:49, 5F

11/10 08:45, , 6F
推(Y),perl豈止噁心,簡直就是邪惡
11/10 08:45, 6F

11/14 11:27, , 7F
Perl 超棒的 ><
11/14 11:27, 7F
文章代碼(AID): #1IRgdFEC (Perl)
討論串 (同標題文章)
文章代碼(AID): #1IRgdFEC (Perl)