stangoesagain has asked for the wisdom of the Perl Monks concerning the following question:
I'm using UI::Dialog to select a file for processing. When I get to this point:
#!/usr/bin/perl use strict; use warnings; use 5.010; use UI::Dialog; my $d = new UI::Dialog ( title => 'SelectFile', order => [ 'kdialog', 'zenity', 'xdialog' ] ); my $fileIn = $d->fselect( path => '/path/to/my/files/' ); say "Selected: $fileIn";
The selected file name prints to the terminal but $fileIn in say "Selected: $fileIn"; line is empty. I swear it worked just a few months ago when I first created this script.
If I initialize $fileIn first and assign it some value, "test", for example, fselect still makes it empty again.
What gives? Is it something system related? I got it working with Tk but Tk doesn't look as nice as KDE's native file selection dialog.
UPDATE: As a workaround I used Capture::Tiny, put fselect into a sub, and chomped the return.
#!/usr/bin/perl use strict; use warnings; use 5.010; use UI::Dialog; use Capture::Tiny ':all'; my $d = new UI::Dialog ( title => 'SelectFile', order => [ 'kdialog', 'zenity', 'xdialog' ] ); sub filename{ my $selected = $d->fselect( path => '/path/to/my/files/' ); return $selected; } my $fileIn = capture_stdout \&filename; chomp $fileIn; #because there's newline at the end of stdout say "Selected: $fileIn";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: UI::Dialog fselect
by Marshall (Canon) on Apr 21, 2016 at 12:09 UTC | |
by stangoesagain (Acolyte) on Apr 21, 2016 at 17:41 UTC |