<[EMAIL PROTECTED]> wrote in message 008801c222a5$a7c3cb10$d381f6cc@david">news:008801c222a5$a7c3cb10$d381f6cc@david... > The reason I explained how to slurp the file into a variable was so that it could be printed anytime > anywhere. My solution does not force the file contents to be printed right away. This is also > useful for if you wish to replace something in the faq before printing it, or adding some to the top > and bottom. In short, it gives the programmer much more control before simply printing the file. > > Regards, > David >
You really didnt need to explain yourself in relpy to my post. Here is a snip from the op's original post: "Kyle Babich" <[EMAIL PROTECTED]> wrote in message 000501c2207c$f543f3e0$be683b41@oemcomputer">news:000501c2207c$f543f3e0$be683b41@oemcomputer... > What would I use to include external pages in my script? (like if I wanted > to print the contents of faq.txt or log.cgi in my script) I was providing the op with an alternative way to get identical results. Sometimes your solution is better, for the reason that you stated, so that the info could be filtered. Sometimes the code I provided is better, for example the file is very large and it is best to avoid loading the data in to memory. Sometimes there are other solutions that are better for other reasons. The point I was trying to make was how print() takes a list of data and not just a simple scalar, a key concept for new perl programmers to understand. It probably took me months to understand it. It had nothing to do at all with your solution. But since your solution involves "turning on slurp mode" I do suggest explaining what that means, and what side effects it could have to the rest of the code. For instance, if your example is used, and later on in the program in the same scope I say: while (<OTHER_FH>) { # oops! It is probably going to confuse someone. Again, someone is back in the newsgroup trying to get help tracking down a very difficult-to-track bug. Probably every example in the docs that show modification of $/ in action have the corresponding code wrapped in a block, i.e. { .... local $/ = undef(); $_ = <FH> .... }. Quick quiz: can anyone explain why? Todd W. > > ----- Original Message ----- > From: "Todd Wade" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Tuesday, July 02, 2002 6:19 PM > Subject: Re: Including External Pages > > > [EMAIL PROTECTED] wrote: > > > open(FH, "</usr/www/domain/faq.txt"); # < for read, > for write, >> for > > append local $/ = undef; # slurp mode (allow for shoving the whole file > > into a scalar) > > my $faq = <FH>; # slurp the whole file into this scalar. > > close(FH); > > > > open(FH, $file) or die("open $file: $!"); > print(<FILE>); # print() takes a list. DWIM in action. > close(FH) or die("close $file: $!"); > > Todd W. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]