mephit has asked for the wisdom of the Perl Monks concerning the following question:
(Yay, $Data::Dumper::Indent) Anyway, I loop through the hash, and for each top level key, find all keys in the next level, and display the image given. The images should be displayed in twos or threes (or however many dupes there are for that particular filename) and wait before going on to the next top-level key. Lather, rinse, repeat.$VAR1 = { 'eggputing-sk.gif' => { '/home/eggie/pics/temp/foo/eggputing-sk.gif' => { 'relname' => './foo/eggputing-sk.gif', 'isize' => '527 x 369', 'inode' => 35022, 'fsize' => 24174 }, '/home/eggie/pics/temp/eggputing-sk.gif' => { 'relname' => './eggputing-sk.gif', 'isize' => '527 x 369', 'inode' => 35022, 'fsize' => 24174 } } };
I have code that works, but I'm no expert on forking and eval and such, so I thought I'd get opinions on it. Read on...
Anyway, Yakko pointed out the Tk chatterbox client, which uses that eval method to spawn off a browser, and said I might be able to use a similar method here, using the image viewer of my choice.foreach my $filename (keys %found) { foreach my $fullfile (sort keys %{ $found{$filename}}) { eval 'my ($pid) = fork; if ($pid == 0) { exec "display -title %d/% +f $fullfile" }'; print $@ if $@; } print "Press <enter> to continue"; <STDIN>; }
I'm pretty sure that I understand how it works, but I don't know if there are any hidden "traps" with eval, fork, or exec that might cause the script to go all wonky on me.
I did a search through the Monestary, and found several references to Parallel::ForkManager. It looks like it would be suitable for this. Plus, it looks like it has a method (wait_all_children()) that would make the press <enter> to continue;<STDIN> lines unnecesary, no?
I don't really care about performance (I don't want it bogging down the machine, though), or portability, as this is mainly a util script for use on my machine only. Readability and safety are what I am concerned with, though. I guess I'm just looking for other options; more goodies for my Perl toolbox, so to speak. Maybe even use Perl itself for the displaying instead of an external program? *shrug*
Any ideas, folks? Thanks.
--
There are 10 kinds of people -- those that understand binary, and those that don't.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Parallel processing, sort of
by theorbtwo (Prior) on Sep 12, 2002 at 21:37 UTC | |
by Preceptor (Deacon) on Sep 13, 2002 at 07:48 UTC | |
Re: Parallel processing, sort of
by dmitri (Priest) on Sep 12, 2002 at 21:31 UTC | |
by mephit (Scribe) on Sep 13, 2002 at 19:05 UTC |