Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: GetOpenFile (Perl::TK 804.028) on v.5.10.0

by Util (Priest)
on Dec 30, 2008 at 04:37 UTC ( [id://733171]=note: print w/replies, xml ) Need Help??


in reply to GetOpenFile (Perl::TK 804.028) on v.5.10.0

To fix your main problem, just change while (<>) to while (<File_Open>) in your Open sub.
The <> is a "null filehandle" (see "I/O Operators" in perlop), which would cause your program to seem to hang because it was waiting (silently) for keyboard input from the DOS window.

Incidentally, 'Ctl+O' should be 'Ctrl+O', and you need to add this line to make the accelerator work:

$main->bind("<Control-o>", \&Open);

Also, here are some improvements to your Open sub; clearer names, tightened variable scope, and correctly handling the user <cancel>ing out of the Open dialog box:

sub Open { my $csv_path = $main->getOpenFile( -filetypes => [ [ 'CSV files', '.csv' ], [ 'All Files', '*' ], ] ); return if not defined $csv_path; open my $csv_fh, '<', $csv_path or die "Cannot open '$csv_path': $!"; my $out_fh; my $last_filename = ''; while (<$csv_fh>) { my ($f) = /^([^,]+),/; my $filename = "$f.txt"; if ( $filename ne $last_filename ) { open $out_fh, '>', $filename or die "cannot open $filename: $!"; } print {$out_fh} $_; $last_filename = $filename; } }

Replies are listed 'Best First'.
Re^2: GetOpenFile (Perl::TK 804.028) on v.5.10.0
by Knoperl (Acolyte) on Dec 30, 2008 at 05:06 UTC

    Dear Most Holy Util,

    You are so much smarter than me. Thank you for getting back to me so soon. You are truly

    AMAZING!!!

    I looked at the perlop and will read it super duper tomorrow. I REALLY APPRECIATE your genius!!!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://733171]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-20 00:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found