#!/usr/bin/perl -w use strict; use Tk; chdir('images'); my @image_files = <*.gif>; #initialize Main Window my $mw = MainWindow->new; show_two_buttons($mw,\@image_files); MainLoop; exit; # Subroutines # sub show_two_buttons{ my $mw = shift; for ($mw->packSlaves()){ $_->destroy() if Tk::Exists($_); #clear out window } my $image_file_REF = shift; my $first_pic = shift @{$image_file_REF}; my $second_pic = shift @{$image_file_REF}; #generate two buttons for my $file ($first_pic,$second_pic){ my $image = $mw->Photo(-file=>$file); $mw->Button( -image=>$image, -text=> $file, -command=>[\&return_array, $mw, $file, $image_file_REF] )->pack(-side=>"left"); } } sub return_array{ my $mw = shift; my $file = shift; my $image_file_REF = shift; push @{$image_file_REF}, $file; # Uncomment to show what's left. #print join ", ", @{$image_file_REF}; #print "\n"; # Here is where we do our test to see what is left if (scalar @{$image_file_REF} > 1) { show_two_buttons($mw, $image_file_REF); } else { print "All done!\n"; exit; } }