in reply to CUPS Printing - Using a Variable as a Filename

Thank you for the prompt and informative replies! I knew that there way a way to do it. Perl rocks!

I have posted the updated code snippit which is now working, below.

Thanks again!

#!/usr/bin/perl -t use strict; use warnings; use Net::CUPS::Destination; use File::Temp qw/tempfile/; my ($filehandle,$filename) = tempfile(UNLINK=>1); # Define Printer my $cups = Net::CUPS->new() or die $!; my $printer = $cups->getDestination("CITIZEN-CT-S801") or die $!; open($filehandle, '>', $filename) or die "Cannot open file for writing +: $!\n"; print $filehandle "Some data 1\n"; print $filehandle "Some data 2\n"; print $filehandle "Some data 3\n"; close($filehandle); # Print Data open($filehandle, '<', $filename) or die "Cannot open file for reading +: $!\n"; if ($printer->printFile($filename, 'jobx')) { print 'Success';} else { my $error = $printer->getError(); if ($error) { print "Printer Error: " . $error . "\n"; } } close($filehandle); exit;

Replies are listed 'Best First'.
Re^2: CUPS Printing - Using a Variable as a Filename
by haukex (Archbishop) on Aug 20, 2019 at 21:47 UTC
    open($filehandle, '>', $filename) or die "Cannot open file for writing +: $!\n"; ... open($filehandle, '<', $filename) or die "Cannot open file for reading +: $!\n"; close($filehandle);

    Note you can remove these lines - tempfile and printFile do this for you. (The first close($filehandle) is still required, but not the second.)