[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [texlive-new] Creating rules file from a single template



On Friday 22 December 2006 05:01, Norbert Preining wrote:
> On Fre, 22 Dez 2006, Mike Bird wrote:
> > Alternatively you could change the design to have myopen
> > return a new file handle.  This makes it easier if you
> > later need to implement recursion such as nested includes.
>
> Code please?

------------- aaa.pm -------------
package aaa;
use Exporter ();
@ISA = qw( Exporter );
@EXPORT_OK = qw (myopen);
@EXPORT = @EXPORT_OK;

sub myopen ($) {
    my ($fn) = @_;
    my $fd;   # Undefined for open
    open($fd, $fn) or die "Cannot open $fn: $!\n";
    return $fd;
}

1;
------------- cat b.pl -------------
use aaa;

my $fd = myopen('aaa.pm'); # Use single quotes wherever
                           # possible to avoid surprises

my @bar = <$fd>;
print "bar=@bar...\n";

close($fd);   # Or create myclose if appropriate

exit(0);
-----------------------------------

--Mike Bird



Reply to: