[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] Location of MAIN code relative to subroutines




I seem to ben having a problem regarding the placement of "MAIN"
code relative to subroutines.

When I execute the following script, the variable $TIME_OFFSET
doesn't seem to have value in the "ParseFile" subroutine.

However, if I move the location of my "MAIN" code (or actually
just the code snip in "MAIN" where $TIME_OFFSET is defined) to
a position before my subroutines, this script appears to work
correctly.

Is this a MacPerl bug, or am I missing something here?
I'm currently using MacPerl 5.2.0r4.

Thanks,

Ero Brown


#========================================================================
#=========================   PERL SCRIPT   ==============================
#========================================================================

# Dump Netscape history in a readable format with the correct
# date-time adjustments when running on a Macintosh.

#========================================================================

#!/usr/bin/perl -w

#========================================================================

use Netscape::History;
use Date::Format;
use Getopt::Long;
use Time::Local;

#========================================================================

sub ReadArguments;
sub ParseFile;

#========================================================================
# Function: ParseFile
#========================================================================

sub ReadArguments
{
    my $res;
    if (@ARGV < 1) {
        die "You must pass in a valid file to process.\n";
    }
    $res = Getopt::Long::GetOptions("i=s" => \$inputFile);
    if (!$inputFile || !(-f $inputFile)) {
        die "An input file must be specified.\n";
    }
}

#========================================================================
# Function: ParseFile
#========================================================================

sub ParseFile {
    my $history, $url, $ftime, $ltime;
    $history = new Netscape::History($inputFile);
    while (defined($url = $history->next_url() )) {
        print "$url :\n";
        $ftime = Date::Format::ctime($url->first_visit_time() + $TIME_OFFSET);
        $ltime = Date::Format::ctime($url->first_visit_time() + $TIME_OFFSET);
        print "    First  : ", $ftime;
        print "    Last   : ", $ltime;
        print "    Count  : ", $url->visit_count(), "\n";
        print "    Expire : ", $url->expire(), "\n";
        print "    Title  : ", $url->title(), "\n";
    }
    $history->close();
}

#========================================================================
#============================   MAIN   ==================================
#========================================================================

my $TIME_OFFSET = 0;
if ($^O eq "MacOS") {
    $TIME_OFFSET = Time::Local::timegm(0,0,0,1,0,70);
}

my $inputFile;

ReadArguments;

ParseFile;


#========================================================================
#============================   END   ===================================
#========================================================================



===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org