Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: Open several files and read line by line

by AnomalousMonk (Archbishop)
on Dec 04, 2015 at 17:57 UTC ( [id://1149403]=note: print w/replies, xml ) Need Help??


in reply to Open several files and read line by line

while (<$filename>){ while (/$id1/g && /$id2/g) { print "$file:$.\n"; } }

I don't understand. If  /$id1/g && /$id2/g ever becomes true (matching by default against  $_ assigned in the outer while-loop), when will it ever become false? I.e., isn't this an infinite loop? And what's the point of the  /g modifier in these regexes? And yes,  $filename is a terrible name for a file handle!

Update: I should have known. Many thanks, choroba. (But  $filename is still terrible!)


Give a man a fish:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^3: Open several files and read line by line
by choroba (Cardinal) on Dec 04, 2015 at 20:51 UTC
    Without /g it would be an infinite loop. But with /g, the matching starts where the last one stopped:
    $_ = "abcabcabc"; while (/c/g && /a/g) { say pos; } __END__ Output: 4 7
    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1149403]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-25 12:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found