There seem to be a few questions here.
What I really want to do, rather than print the file descriptor view, is to work with the contents of the files themselves.
The reason print $fh returns GLOB(0x1a457de8) is because the $fh scalar is a file descriptor, not the contents of the file itself. To access the contents of the file itself, use <$fh> . For instance:
while (my $line = <$fh>) { print $line; }
prints the contents of the entire file.
This is described in pelrdoc perlop :
If what the angle brackets contain is a simple scalar variable (for example, <$foo> ), then this variable contains the file descriptor name for the input or its type global or a reference to the same.
But it has already been tested!
I see it. Try changing the opening mode to +< .
According to perldoc perlfaq5 :
How is it that when I open a file for reading and writing, it wipes it?
Because you are using something like this, which truncates the file then gives you read and write access:
open my $fh, '+>', '/path/name';
Oops Instead, you should use this to fail if the file does not exist:
open my $fh, '+<', '/path/name';
Using ">" always clobbers or creates. Using "<" will never be. "+" does not change this.
It goes without saying that < or die $! recommended or die $! after open .
But take a step back.
There is a more Perlish way to back up the source file and then manipulate it. In fact, this can be done using the command line itself (!), Using the -i flag:
$ perl -p -i._extjs4 -e 's/foo/bar/g' *.js
See perldoc perlrun .
I cannot satisfy my command line needs.
If the manipulation is too large to process the command line, Tie::File worth it.