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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

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


Nov 5, 2007, 1:56 PM

Views: 4607
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.

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

#! /usr/bin/perl
require '';

$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