By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,541 Members | 1,455 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,541 IT Pros & Developers. It's quick & easy.

doubt on while

P: 51
I have been studying programming perl. There I have come across a code something as below:

Expand|Select|Wrap|Line Numbers
  1.  while (<FILE>) {
  2.     print if /http:/;
  3.     print if /ftp:/;
  4.     print if /mailto:/;
  5.     # What next?
  6. }
Can u please tell me what is FILE there?

Jun 2 '08 #1
Share this Question
Share on Google+
2 Replies

Expert 100+
P: 410
FILE is the file handler for the file that you are reading. When you want to process a file, you have to change/redirect the input stream/ output stream to the file. For this purpose, a file-handle is created when you use open() function.
Expand|Select|Wrap|Line Numbers
  1. open(FILE,"data.txt") or die "opening file failed";
When you assign this file-handle within angular brackets to an array
Expand|Select|Wrap|Line Numbers
  1. @data=<FILE>;
The array would contain entire content of file with each line in file as each element in the array(as '\n' is the default input record separator)
When you assign it to a scalar, it would contain the first line of file:
Expand|Select|Wrap|Line Numbers
  1. $data=<FILE>;
In your code, while(<FILE>) {} loop will iterate through the file, one line at a time.

I would suggest you to go through Files and Data
Jun 2 '08 #2

P: 9
If you want some basic stuff about files, check [DELETED]
Jul 8 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.