#!/usr/bin/perl use strict; use warnings; my @pics; my $test_do_insert = 1; #change value to 0 to change variables to test a case where it should not insert my $image_name_1 = ""; $image_name_1 = "test_image1.jpg" if (!$test_do_insert); $pics[0] = 'test1.jpg'; my $image_name_2 = ""; #$image_name_2 = "test_image2.jpg" if (!$test_do_insert); $pics[1] = "test2.jpg"; my $image_name_3 = ""; #$image_name_3 = "test_image3.jpg" if (!$test_do_insert); $pics[2] = "test3.jpg"; my $image_name_4 = ""; #$image_name_4 = "test_image4.jpg" if (!$test_do_insert); $pics[3] = "test4.jpg"; if (@pics) { my $flag_pic = 0; # while (my $row = $sth->fetchrow_hashref()) { $flag_pic += &check_empty($image_name_1, $pics[0]); print $flag_pic."\n"; $flag_pic += &check_empty($image_name_2, $pics[1]); print $flag_pic."\n"; $flag_pic += &check_empty($image_name_3, $pics[2]); print $flag_pic."\n"; $flag_pic += &check_empty($image_name_4, $pics[3]); print $flag_pic."\n"; # } print "
751**$flag_pic**
"; # End check if ( $flag_pic == 0 ) { print "doing insert"; } else { print "not doing insert"; } } sub check_empty() { my $img = shift; my $pic = shift; if ( $img ne "" && $pic ne "" ) { return 1; } else { return 0; } }