In my current mini-project, I end up with a structure of hashes like such:
$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 } } };
(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.

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...

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>; }
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.

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.


In reply to Parallel processing, sort of by mephit

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.