I'm trying to bring some old 4.X code up to 5.8. I'm still confused about using strings as filehandles. The tutorial section at File Input and Output says
Of course, with just a little 'improvement' this loses:open(FILE, "data.txt"); #opens data.txt in read-mode while(<FILE>){ #reads line by line from FILE which i +s the filehandle for data.txt chomp; print "Saw $_ in data.txt\n"; #shows you what we have read } close FILE;
Gives the dreaded:use strict; my($foo) = 'FILE'; open($foo, "data.txt"); #opens data.txt in read-mode while(<$foo>){ #reads line by line from FILE which i +s the filehandle for data.txt chomp; print "Saw $_ in data.txt\n"; #shows you what we have read } close $foo; #close the file.
Oddly, looking through the various tutorials, I can't find a good example of creating a filehandle, binding it to a variable, and passing it around (e.g. as an arg to a subroutine.) What's the ''recomended'' way to do this?
thanks,
throop
In reply to Still blurry on variables for filehandles by throop
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |