Autovivification - File and Directory Handles

File and Directory Handles

Perl 5.6.1 and newer support autovivification of file and directory handles. Calling open on an undefined variable will set it to a filehandle. According to perl561delta, "his largely eliminates the need for typeglobs when opening filehandles that must be passed around, as in the following example:

for my $file ( qw(this.conf that.conf) ) { my $fin = open_or_throw('<', $file); process_conf( $fin ); # no close needed } use Carp; sub open_or_throw { my ($mode, $filename) = @_; open my $h, $mode, $filename or croak "Could not open '$filename': $!"; return $h; }

Read more about this topic:  Autovivification

Famous quotes containing the words file and/or directory:

    Probably nothing in the experience of the rank and file of workers causes more bitterness and envy than the realization which comes sooner or later to many of them that they are “stuck” and can go no further.
    Mary Barnett Gilson (1877–?)

    An actor who knows his business ought to be able to make the London telephone directory sound enthralling.
    Donald Sinden (b. 1923)