Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Perl tk - open file and print content

by Giorgio C (Novice)
on Jan 16, 2012 at 12:07 UTC ( #948126=perlquestion: print w/ replies, xml ) Need Help??
Giorgio C has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, i'm a newbie in perl and tk module. I was able to create a little menu wit the option get_open file so to visualize a little windows with all the file in my PC. Then i select the file i like to visualize and is opened. The problem is that i don't understand how to print on a windows the text of the opened file. The code is:
$file->command ( -label => 'Open', -accelerator => 'Ctrl-o', -underline => 0, -command => \&open_file); $mw->bind('<Control-o>', [\ +&open_file]); #SUPPORTED FILES TO OPEN my $types_OPEN = [ ['text files', '.txt'], ['All Files', '*'],]; sub open_file { my $open = $mw->getOpenFile(-filetypes => $types_OPEN, + -defaultextension => '.txt'); print qq{You chose to open "$open"\n} if $open; my $open = $mw; }
I would like to print the content of the txt file opened in a window of the program. Could anybody help me ? Thank you

Comment on Perl tk - open file and print content
Download Code
Re: Perl tk - open file and print content
by Anonymous Monk on Jan 16, 2012 at 12:24 UTC
Re: Perl tk - open file and print content
by zentara (Archbishop) on Jan 16, 2012 at 15:05 UTC
    I would like to print the content of the txt file opened in a window of the program. Could anybody help me ?

    Do you just want to print from the filename itself? Or do you want to open the file in an editor to see it, before you print it? In either case, you probably would use the same code in the callbacks. For MS Windows I would use a Windows only module, but on Linux you can use Net::CUPS::Printer, or use a forked system call to run the lpr command. You could also print directly to the printer, if you wanted more control.

    open(LPR, "|lpr -Plp0 >/dev/null 2>&1"); open (FILE,"< $0 ") or die "Couldn't open: $!"; my $text = do {local $/; <FILE>}; close FILE; print LPR $text; close LPR;
    or use the module
    #!/usr/bin/perl use warnings; use strict; use Net::CUPS::Printer; use Data::Dumper; my @printers = cupsGetPrinters (); print "printers-> @printers\n"; my $printer = cupsGetDefault(); print "Default printer-> $printer\n"; my %options =(); my $jobid = cupsPrintFile($printer,"./$0",'Job1',\%options); print "jobid-> $jobid\n"; my $jobs = cupsGetJobs('lp0',1,0); print "jobs-> $jobs\n"; print Dumper([$jobs]),"\n"; my $cancel = cupsCancelJob('lp0', $jobid); print "cancel-> $cancel\n"; #my $jobs = cupsGetJobs('lp0',1,0); #print "jobs-> $jobs\n"; #print Dumper([$jobs]),"\n"; my $user = cupsUser(); print "user-> $user\n"; exit;

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh

      OP said

      to print the content of the txt file opened

      in a window of the program.

        Thanks you very much ! I wanted to print directly the opned txt content in a GUI windows.
      I try to install Net::CUPs from cpan shell i got this massage: Running install for module 'Net::CUPS' Running make for D/DH/DHAGEMAN/Net-CUPS-0.61.tar.gz Has already been unwrapped into directory /home/casaburi/.local/share/.cpan/build/Net-CUPS-0.61-_zchLs No 'Makefile' created , won't make Running make test Make had some problems, won't test Running make install Make had some problems, won't install SO i try to install it manually getting this error massage: Net::CUPS Configuration Running cups-config ... failed. Net::CUPS requires the Common Unix Printing System. Check your system configuration and then attempt the configure process again. (i have perl v5.10.1 on Ubuntu) Can anyone help me please ? i'm going crazy !
        SO i try to install it manually getting this error massage: Net::CUPS Configuration Running cups-config ... failed. Net::CUPS requires the Common Unix Printing System. Check your system configuration and then attempt the configure process again. (i have perl v5.10.1 on Ubuntu) Can anyone help me please ? i'm going crazy !

        On Ubuntu, you should first use the apt-get or Synaptics Package Manager to install Perl modules. Why? Because Ubuntu often has many dependencies, that are required before installation. I would look thru your menu, and find Synaptic's Package Manager, run it and search for "perl Net::Cups", then install all the dependencies.

        Also, unless you have the latest Perl version 14.x installed, the Perl that comes with Ubuntu is older, around version 10 or 12, and the latest Net::Cups may not work at those Perl version levels. You may need an earlier release of the Net::CUPS module to be compatible. See Cups on Ubuntu


        I'm not really a human, but I play one on earth.
        Old Perl Programmer Haiku ................... flash japh

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://948126]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (3)
As of 2014-09-21 17:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (173 votes), past polls