#!/usr/bin/perl -w use Tk; chdir('images'); my @image_files = <*.gif>; #initialize Main Window my $mw = MainWindow->new; #eventually I want to have this part continue until only one image remains while (scalar @image_files > 1){ my $pic1 = shift @image_files; my $pic2 = shift @image_files; @image_files = show_two_buttons($mw, $pic1,$pic2,\@image_files); } #do something when we have one picture left. #dosomething(); MainLoop; sub show_two_buttons{ my $mw = shift @_; for ($mw->packSlaves()){ $_->destroy() if Tk::Exists($_); #clear out window } my $first_pic = shift @_; my $second_pic = shift @_; my @image_files = @{shift @_}; #generate two buttons for $file($first_pic,$second_pic){ my $image = $mw->Photo(-file=>$file); #cant figure how to return or pass arrays on the command here $mw->Button( -image=>$image, -text=> $file, -command=>[\&return_array, $file, \@image_files] )->pack(-side=>"left"); } return @image_files;#array never changes } sub return_array{ my $file = shift @_; my @image_files = @{shift @_}; push @image_files, $file; print @image_files; #only contains one file return @image_files;#doesn't return to anything }