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

How to open file whose name is stored in a variable

P: 4
How can I open a file whose file name is stored in a variable

Thank you in advance
May 27 '10 #1
Share this Question
Share on Google+
1 Reply


Expert
P: 70
The following will try to open the file named foo.txt for input:
Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3.  
  4. my $filename = 'foo.txt';
  5. open my $fh, '<', $filename or die "can not open file $filename: $!";
  6.  
There is a tutorial:
Expand|Select|Wrap|Line Numbers
  1. perldoc opentut
  2.  
May 27 '10 #2

Post your reply

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