/ Published in: Perl
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
## Define three types printers: 1.Pipe to less, 2.Output to a file 3.Just print ## ## sub getLessPrinter { my $pout= IO::File->new( "| less" ) or croak "Failed to create less pipe\n"; } # closure } # getLessPrinter sub getFilePrinter { my $fout= IO::File->new( "> $file" ) or croak "Failed to create file: $file: $!\n"; } # closure } # getFilePrinter sub getNoLessPrinter { } # closure } # getNoLessPrinter ## Then select one of the printer ## ## my $printer= getFilePrinter( "output.txt"); ## or ## my $printer= getNoLessPrinter(); ## or my $printer= getLessPrinter(); $printer->( "Something to print.\n");