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:
<DATA> FILEHANDLE

 



jigneshjsoni
User

Apr 18, 2008, 7:36 AM

Post #1 of 2 (364 views)
<DATA> FILEHANDLE Can't Post

print "Content-Type: text/html\n\n";for ( <DATA> ) { #skip blank lines next if /^$/; ($key, $value) = split /\s*,\s*/; $hyperlink{$key} = $value; #Once you've printed the header, #you can print diagnostics to the browser window! print "$key, $value<br>\n";}open HTML, "editing.html" or die $!;while( <HTML> ) { for $key ( keys %hyperlink ) { s(\s$key\s) ( <a href="$hyperlink{$key}" style="background:silver">$key</a> ); } print;}close HTML;__DATA__special, http://www.m-w.comcode, javascript:alert('Code!')example, course/index.html

In this example (taken from www.gossland.com), filehandle (<DATA>) is used with FOR loop and (<HTML>) is used with WHILE loop. Can we use FOR loop with (<HTML>) and WHILE loop with (<DATA>) ?




KevinR
Veteran


Apr 18, 2008, 12:42 PM

Post #2 of 2 (361 views)
Re: [jigneshjsoni] <DATA> FILEHANDLE [In reply to] Can't Post

using "for" on a filehandle is not a common practice. Generally you would use "while" when reading in a file. They each loop through a file but "while" checks for EOF but "for" does not. "for" is really a list control not a file I/O control.

There might be a reason the code uses "for" instead of "while" that I am not aware of though.

Next time post formatted code that can be read.
-------------------------------------------------

 
 


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

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