Thanks, both chromatic and japhy,

yeah, I still have some to learn on when to use quoting and when not to...

I've fixed a couple of silly mistakes, and documented it, so I'll post the code below, just in case anyone's interested in using / abusing it.

This is my first attempt at OO perl, after reading the docs yesterday, and I'm very impressed at it's abilities.
I've written this little package with the intention of cleaning up a CGI script I'm working on, and can already see so many possibilities in expanding this package alone, as well as other areas of my script.
Thanks for the help, guys.
#!/usr/bin/perl -wT use strict; my $d = data->new; print $d->hour($d->now('h')), ":"; print $d->minute($d->now('m')), ":"; print $d->second($d->now('s')), " - "; print $d->day($d->now('D')), " day of "; print $d->month($d->now('M')), " "; print $d->year($d->now('Y')), "\n";; { package data; ######################### #Call a new package with # my $d = data->new; # #Grab the localtime #(of when a new package was initialized) #with # $d->now('s'); #seconds # $d->now('m'); #minutes # $d->now('h'); #hour # $d->now('D'); #day # $d->now('M'); #month # $d->now('Y'); #year # #"Nicely" format with # my $value = 1; # $d->day($value); #returns "1st" # $d->month($value); #returns "January" ########################## sub new { my $proto = shift; my $class = ref($proto) || $proto; my @now = localtime(); $now[0] += 1; #format the seconds $now[1] += 1; #format the minutes $now[2] += 1; #format the hour $now[4] += 1; #format the month $now[5] += 1900; #format the year my $self = {}; $self->{now_second} = $now[0]; $self->{now_minute} = $now[1]; $self->{now_hour} = $now[2]; $self->{now_day} = $now[3]; $self->{now_month} = $now[4]; $self->{now_year} = $now[5]; bless ($self, $class); return $self; } sub now { my $self = shift; my $type = shift; if ($type eq 's') { return $self->{now_second}; } elsif ($type eq 'm') { return $self->{now_minute}; } elsif ($type eq 'h') { return $self->{now_hour}; } elsif ($type eq 'D') { return $self->{now_day}; } elsif ($type eq 'M') { return $self->{now_month}; } elsif ($type eq 'Y') { return $self->{now_year}; } } sub second { my $self = shift; my $value = shift; return $value; } sub minute { my $self = shift; my $value = shift; return $value; } sub hour { my $self = shift; my $value = shift; #line 69 return $value; } sub day { my $self = shift; my $value = shift; if ($value == 1) { "1st" } elsif ($value == 2) { "2nd" } elsif ($value == 3) { "3rd" } elsif ($value == 21) { "21st" } elsif ($value == 22) { "22nd" } elsif ($value == 23) { "23rd" } elsif ($value == 31) { "31st" } elsif (($value >= 4) && ($value <= 31)) { return $value . "th"; } else { "invalid day" } } sub month { my $self = shift; my $value = shift; if ($value == 1) { "January" } elsif ($value == 2) { "February" } elsif ($value == 3) { "March" } elsif ($value == 4) { "April" } elsif ($value == 5) { "May" } elsif ($value == 6) { "June" } elsif ($value == 7) { "July" } elsif ($value == 8) { "August" } elsif ($value == 9) { "September" } elsif ($value == 10) { "October" } elsif ($value == 11) { "November" } elsif ($value == 12) { "December" } else { "invalid month" } } sub year { my $self = shift; my $value = shift; return $value; } }

In reply to Re: OO reference problem by fireartist
in thread OO reference problem by fireartist

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.