G'day Buttonzz,

Welcome to the Monastery.

"I wanted to keep it quite theoretically because I dont want anyone to do my work ..."

This is most laudable! However, a little more practical information wouldn't have hurt. By "GridColumn" I'll assume you mean Tk::GridColumns. Do note that many module names are very similar: it's best to provide a link so we're all on the same page (see "What shortcuts can I use for linking to other information?"). It's unclear what "the menu's subs" refers to: some code to indicate what you'd tried would have helped. In general, a minimal example of what you've attempted allows us to help you better; for GUIs, leave out all the cosmetic code (colours, fonts, padding, etc.) and just concentrate on the main parts (basic layout, callbacks, and so on). Probably not necessary in this case but, with GUIs, a minimal piece of ASCII art is often far more enlightening than a lengthy, prosaic description.

"Im dealing with two problems."

Problem I: I'm guessing your issue is references. In the code I provide below, there's a &build_menu with "$$gc_ref->refresh;": "$gc_ref" is a reference to "$gc". The documentation I linked to has "$gc->refresh;" in several places: I'm assuming that's the same method you're referring to.

Problem II: Again, with no code, it's difficult to know where you're having difficulties. The usual solution, in this type of situation, is to populate a hash with data you collect, then access that later for whatever processing is required. In the code I provide below, there's &_get_exif_data which collects data in a hash (as a hashref: "$exif_data"); and &_populate_grid which subsequently uses it. Both of those subroutines are called from a callback in &build_menu.

In &_get_exif_data, you'll see that only one Image::ExifTool object is instantiated and reused on every call. Also note that it only extracts information once per filetype per directory: if your directory contents are changing, you may want to handle that differently. I've only stored the file type information for this code example: it sounds like you'll want more than this; however, the underlying technique should still be sound.

One thing to note about the following code is that all variables are lexical (using my) and all have a very limited scope. There are no variables at the file-scope level; and anonymous blocks have been used to further restrict their scope within subroutines. Where variables have been passed around as function arguments, a reference to the variable, rather than the variable itself, has been used (in nearly every case): this is particularly important with callbacks (which often simply won't work, or will fail in hard-to-track-down ways, if you don't do this).

#!/usr/bin/env perl use strict; use warnings; use autodie; use File::Spec; use Image::ExifTool; use Tk; use Tk::LabFrame; use Tk::GridColumns; build_gui(MainWindow::->new); MainLoop; sub build_gui { my ($mw) = @_; $mw->geometry('400x500+50+50'); build_ctrl($mw); { my $exif_data = {}; my ($gc, @gdata); build_menu($mw, \$exif_data, \$gc, \@gdata); build_grid($mw, \$gc, \@gdata); } } sub build_menu { my ($mw, $exif_data_ref, $gc_ref, $gdata_ref) = @_; my $frame = $mw->LabFrame(-label => 'Menu', -labelside => 'acrosst +op') ->pack(-fill => 'x'); my $dir_frame = $frame->Frame->pack(-fill => 'x'); my $ext_frame = $frame->Frame->pack(-fill => 'x'); my $pop_frame = $frame->Frame->pack(-fill => 'x'); my $directory = 'pm_1201345_test_files'; my $extensions = ''; $dir_frame->Label(-text => 'Directory: ')->pack(-side => 'left'); $dir_frame->Label(-textvariable => \$directory)->pack(-side => 'le +ft'); $ext_frame->Label(-text => 'Extensions: ')->pack(-side => 'left'); $ext_frame->Entry(-textvariable => \$extensions)->pack(-side => 'l +eft'); $pop_frame->Button(-text => 'Populate Grid', -command => sub { _get_exif_data($exif_data_ref, \$directory, \$extensions); _populate_grid(\$gdata_ref, $exif_data_ref, \$directory, \$ext +ensions); $$gc_ref->refresh; })->pack(-side => 'left'); return; } sub build_grid { my ($mw, $gc_ref, $gdata_ref) = @_; my $frame = $mw->LabFrame(-label => 'Grid', -labelside => 'acrosst +op') ->pack(-fill => 'both', -expand => 1); my @cols; $$gc_ref = $frame->GridColumns(-data => $gdata_ref, -columns => \@ +cols) ->pack(-fill => 'both', -expand => 1); @cols = ( { -text => 'Pathname', -weight => 1 }, { -text => 'File Type' }, ); $$gc_ref->refresh; return; } sub build_ctrl { my ($mw) = @_; my $frame = $mw->LabFrame(-label => 'Controls', -labelside => 'acr +osstop') ->pack(-side => 'bottom', -fill => 'x'); $frame->Button(-text => 'Exit', -command => sub { exit })->pack; return; } { my $exif; BEGIN { $exif = Image::ExifTool::->new } sub _get_exif_data { my ($exif_data, $dir, $exts) = map { $$_ } @_; my @unseen_exts = grep { ! exists $exif_data->{$dir}{$_} } spl +it ' ', $exts; return unless @unseen_exts; my $ext_re = '[.](' . join('|', @unseen_exts) . ')$'; { opendir(my $dh, $dir); while (readdir $dh) { next unless /$ext_re/; my $path = File::Spec::->catfile($dir, $_); $exif->ExtractInfo($path); $exif_data->{$dir}{$1}{$path} = $exif->GetValue('FileT +ype'); } } return; } } sub _populate_grid { my ($gdata_ref, $exif_data, $dir, $exts) = map { $$_ } @_; @$gdata_ref = (); for my $ext (sort split ' ', $exts) { for my $path (sort keys %{$exif_data->{$dir}{$ext}}) { push @$gdata_ref, [$path, $exif_data->{$dir}{$ext}{$path}] +; } } return; }

To test this code, I created a directory called "pm_1201345_test_files", and populated it with a variety of PNG, SVG and WAV files.

— Ken


In reply to Re: Questions regarding mixing up all the data from Image::ExifTool by kcott
in thread Questions regarding mixing up all the data from Image::ExifTool by Buttonzz

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.