467,114 Members | 1,316 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,114 developers. It's quick & easy.

doubt on while

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
  • viewed: 1030
2 Replies
Expert 256MB
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
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.

Similar topics

138 posts views Thread by ambika | last post: by
3 posts views Thread by orium69@gmail.com | last post: by
11 posts views Thread by krishnamaddi@gmail.com | last post: by
77 posts views Thread by muttaa | last post: by
6 posts views Thread by edu.mvk | last post: by
51 posts views Thread by deepak | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.