
hoptar
Novice
Nov 5, 2007, 1:56 PM
Post #1 of 16
(893 views)
|
|
subfunction return (true/false)
|
Can't Post
|
|
Hi Guys, this is really basic, but after 3 hours or research, I still can't get it right.. I have simple sub called "checkdate" in file1. checkdate takes 2 arguments: filename1, filename2, and should return true/false depending on which file is older. This subfunction, needs to be called from various other files (let's say file 2 for now.) Based on the return value, the script in file2 will either continue or die. But the "return" value always appears to be the "0" . I added it below the subfunction to make it "return a true value" How do I go about getting the "real" return value in file2 without getting the error? Thanks for the help. File1: sub check_date ## Begin Check_date. { chomp @ARGV; my @FN0 = split('\.',$ARGV[0]); my @FN1 = split('\.',$ARGV[1]); ... ... $D0 = $FN0[1]; $D1 = $FN0[1]; # if ($D1 > $D0) { # return 1; # print "D1 greater than D0\n"; # } # else { # return 0; # print "D0 greater than D1\n"; # } return ($D1 > $D0); } ## End Check_date 1 File2: #! /usr/bin/perl require 'checkdate.pl'; $A = &check_date ("abcd.041101.gz" , "wxyz.061001.gz"); if ($A) { print "True\n"; } else { die ("Existing file is the newer version."); }
(This post was edited by hoptar on Nov 6, 2007, 9:27 AM)
|