in reply to Use of Typeglob

Example one:

open(FILE, '>', 'temp.txt') or die("Can't create output file: $!"); greet(*FILE); sub greet { my ($fh) = @_; print $fh "Hello World\n"; }

Example two:

sub foo { print("Hello World\n"); } *bar = \&foo; bar();

Most scripts don't use typeglobs. They just reap the benefits of very special modules which use them. For example, Exporter and constant might use typeglobs to import the symbols into the caller's namespace.

The top example can be rewritten without typeglobs. It's safer without them.

open(my $file, '>', 'temp.txt') or die("Can't create output file: $!"); greet($file); sub greet { my ($fh) = @_; print $fh "Hello World\n"; }

Note how greet didn't change? Where file handles are concerned, typeglobs, ref to typeglobs and IO::Handle objects are almost always interchangable.