CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: open and close file before each while-looping through file?: Edit Log



Drinc3
New User

Sep 12, 2013, 8:47 AM


Views: 1539
open and close file before each while-looping through file?

I recognized that in the following code the second while-loop doesn't take in the file once more. With an additional opening and closing it seems to work well. Is that intented?
[perl]
open ($file, "< filename.txt");

while (<$file>) {
m/(keyword) (.+)/;
push @keywords, $2;
}

while (<$file>) {
m/(other_keyword) (.+)/;
push @other_keywords, $2;
}
print @keywords;
print @other_keywords;
[/perl]

EDIT: Why isn't the code properly formatted?
EDIT2: Why is it I can't find the button for watching a thread? That is kind of embarrassing.


(This post was edited by Drinc3 on Sep 12, 2013, 8:57 AM)


Edit Log:
Post edited by Drinc3 (New User) on Sep 12, 2013, 8:50 AM
Post edited by Drinc3 (New User) on Sep 12, 2013, 8:57 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives