Gossamer Forum
Home : Products : Gossamer Links : Discussions :

simple $day question

Quote Reply
simple $day question
hi GT'ers

the goal of the following global sub is to return either 01 (if the day is 01-14) or 15 (if the day is 15 or greater), and it works just fine:

sub {
my $date = GT::Date::date_get();
my $day = substr($date, 8,2);
my $part = ($day < 15 ? '01' : '15');
return {check_date => $part};
}

now, however, i want it to return either 01 (if day is 01-07), 08 (if day is 08-14), 15 (if day is 15-21), or 22 (if day is greater than 21)... any ideas on how i need to change my $part ???? i'm failing at it... thanks for helping a novice learn

-kysa
Quote Reply
Re: [kysa] simple $day question In reply to
i've been trying this:

sub {
my $date = GT::Date::date_get();
my $day = substr($date, 8,2);
if ($day < 8) {
my $part = '01';
} elsif ($day < 15) {
my $part = '08';
} elsif ($day < 22) {
my $part = '15';
} elsif ($day > 21) {
my $part = '22';
}
return {check_date => $part};
}

but keep getting the error: "Global symbol "$part" requires explicit package name at (eval 795) line 13."
Quote Reply
Re: [kysa] simple $day question In reply to
i think this fixed it... will find out tomorrow:

sub {
my $date = GT::Date::date_get();
my $day = substr($date, 8,2);
my $part = ($day < 8 ? '01' : ($day < 15 ? '08' : ($day < 22 ? '15' : '22')));
return {check_date => $part};
}
Quote Reply
Re: [kysa] simple $day question In reply to
Try;

Code:
use GT::Date;
my $date = GT::Date::date_get();
my ($day,$month,$year) = split /-/, $date;

if (length ($day) < 2) {
$day = '0'.$day;
}
return $day;

Untested, but should work.

Basically, if the length of $day == 1 charachter, then pad it with a 0.

NB: You may need to change the order of this part;

($day,$month,$year)

... as I'm not sure exactly what format you are using =)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] simple $day question In reply to
thanks andy! i'll give it a spin!