CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: subfunction return (true/false): Edit Log



hoptar
Novice

Nov 5, 2007, 1:56 PM


Views: 1667
subfunction return (true/false)

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)


Edit Log:
Post edited by hoptar (Novice) on Nov 6, 2007, 9:27 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives