Need some help...

Discussion in 'Perl Misc' started by warpman, Nov 19, 2003.

  1. warpman

    warpman Guest

    I need some help. I'm new to perl and I have borrow the following
    code. This sub keeps on given me the following date:

    November 5, 103 at 10:16:33:

    I don't understand why it keeps on given me the year as 1xx instead of
    2 digits. Any help would be greatly appreciated. Thanks in advanced.



    =====
    sub get_variables {

    if ($FORM{'followup'}) {
    $followup = "1";
    @followup_num = split(/,/,$FORM{'followup'});
    $num_followups = @followups = @followup_num;
    $last_message = pop(@followups);
    $origdate = "$FORM{'origdate'}";
    $origname = "$FORM{'origname'}";
    $origsubject = "$FORM{'origsubject'}";
    }
    else {
    $followup = "0";
    }

    if ($FORM{'name'}) {
    $name = "$FORM{'name'}";
    $name =~ s/"//g;
    $name =~ s/<//g;
    $name =~ s/>//g;
    $name =~ s/\&//g;
    }
    else {
    &error(no_name);
    }

    if ($FORM{'email'} =~ /.*\@.*\..*/) {
    $email = "$FORM{'email'}";
    }

    if ($FORM{'subject'}) {
    $subject = "$FORM{'subject'}";
    $subject =~ s/\&/\&amp\;/g;
    $subject =~ s/"/\&quot\;/g;
    }
    else {
    &error(no_subject);
    }

    if ($FORM{'url'} =~ /.*\:.*\..*/ && $FORM{'url_title'}) {
    $message_url = "$FORM{'url'}";
    $message_url_title = "$FORM{'url_title'}";
    }

    if ($FORM{'img'} =~ /.*tp:\/\/.*\..*/) {
    $message_img = "$FORM{'img'}";
    }

    if ($FORM{'body'}) {
    $body = "$FORM{'body'}";
    $body =~ s/\cM//g;
    $body =~ s/\n\n/<p>/g;
    $body =~ s/\n/<br>/g;

    $body =~ s/&lt;/</g;
    $body =~ s/&gt;/>/g;
    $body =~ s/&quot;/"/g;
    }
    else {
    &error(no_body);
    }

    if ($quote_text == 1) {
    $hidden_body = "$body";
    $hidden_body =~ s/</&lt;/g;
    $hidden_body =~ s/>/&gt;/g;
    $hidden_body =~ s/"/&quot;/g;
    }

    ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
    localtime(time);

    if ($sec < 10) {
    $sec = "0$sec";
    }
    if ($min < 10) {
    $min = "0$min";
    }
    if ($hour < 10) {
    $hour = "0$hour";
    }
    if ($mon < 10) {
    $mon = "0$mon";
    }
    if ($mday < 10) {
    $mday = "0$mday";
    }

    $month = ($mon + 1);

    @months = ("January","February","March","April","May","June","July","August","September","October","November","December");

    if ($use_time == 1) {
    $date = "$hour\:$min\:$sec $month/$mday/$year";
    }
    else {
    $date = "$month/$mday/$year";
    }
    chop($date) if ($date =~ /\n$/);

    $long_date = "$months[$mon] $mday, $year at $hour\:$min\:$sec";
    # $long_date = "$months[$mon] $mday, 19$year at $hour\:$min\:$sec";
    }
     
    warpman, Nov 19, 2003
    #1
    1. Advertising

  2. warpman

    Xaonon Guest

    Ned i bach <>, warpman
    <> teithant i thiw hin:

    > I need some help. I'm new to perl and I have borrow the following
    > code. This sub keeps on given me the following date:
    >
    > November 5, 103 at 10:16:33:
    >
    > I don't understand why it keeps on given me the year as 1xx instead of
    > 2 digits. Any help would be greatly appreciated. Thanks in advanced.


    perldoc -f localtime

    -> $year is the number of years since 1900. That is, $year is 123 in year
    -> 2023.... The proper way to get a complete 4-digit year is simply:
    ->
    -> $year += 1900;

    --
    Xaonon, EAC Chief of Mad Scientists and informal BAAWA, aa #1821, Kibo #: 1
    http://xaonon.dyndns.org/ Guaranteed content-free since 1999. No refunds.
    "Uploading isn't a >H goal because it's one step closer to some mythical and
    unknowable perfection, but because it'll be jolly practical." -- Rich Artym
     
    Xaonon, Nov 19, 2003
    #2
    1. Advertising

  3. warpman

    Xaonon Guest

    Ned i bach <>, warpman
    <> teithant i thiw hin:

    > I need some help. I'm new to perl and I have borrow the following
    > code. This sub keeps on given me the following date:
    >
    > November 5, 103 at 10:16:33:
    >
    > I don't understand why it keeps on given me the year as 1xx instead of
    > 2 digits. Any help would be greatly appreciated. Thanks in advanced.


    perldoc -f localtime

    -> $year is the number of years since 1900. That is, $year is 123 in year
    -> 2023.... The proper way to get a complete 4-digit year is simply:
    ->
    -> $year += 1900;
    ->
    -> And to get the last two digits of the year (e.g., '01' in 2001) do:
    ->
    -> $year = sprintf("%02d", $year % 100);

    --
    Xaonon, EAC Chief of Mad Scientists and informal BAAWA, aa #1821, Kibo #: 1
    http://xaonon.dyndns.org/ Guaranteed content-free since 1999. No refunds.
    "Uploading isn't a >H goal because it's one step closer to some mythical and
    unknowable perfection, but because it'll be jolly practical." -- Rich Artym
     
    Xaonon, Nov 19, 2003
    #3
  4. (warpman) writes:
    > I need some help. I'm new to perl and I have borrow the following
    > code. This sub keeps on given me the following date:
    >
    > November 5, 103 at 10:16:33:
    >
    > I don't understand why it keeps on given me the year as 1xx instead of
    > 2 digits. Any help would be greatly appreciated. Thanks in advanced.


    If in doubt, read the documentation:

    $ perldoc -f localtime

    If you get undesired output from a function, it's best to figure out
    whether its your expectations or its that are being confounded.

    In this specific case, I'd recommend you use the strftime() function
    from the POSIX module. 'perldoc POSIX' for more info.

    -=Erc
    --
    Come to think of it, there are already a million monkeys on a million
    typewriters, and Usenet is NOTHING like Shakespeare.
    -- Blair Houghton.
     
    Eric Schwartz, Nov 19, 2003
    #4
  5. warpman

    Uri Guttman Guest

    put the subject in the subject of the post.

    did you steal/borrow/copy this code or create this mess yourself? it
    looks like typical old cargo cult crap.

    this code is so perl4ish and so clunky.

    jeez, a y2k bug 3 years later.

    rtfm some more on localtime.

    no strict

    some unseen and probably bad cgi parser is used

    quoted scalar variables

    it is not worth fixing. dump it all and rewrite it.

    you should learn some perl from a better source too.

    uri

    --
    Uri Guttman ------ -------- http://www.stemsystems.com
    --Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
    Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
     
    Uri Guttman, Nov 19, 2003
    #5
  6. warpman wrote:
    > ... I have borrow the following code.


    You should not use fragments of other people's code if you don't
    understand how it works!

    > This sub keeps on given me the following date:
    >
    > November 5, 103 at 10:16:33:
    >
    > I don't understand why it keeps on given me the year as 1xx instead
    > of 2 digits.


    Well, you have this line:

    $long_date = "$months[$mon] $mday, $year at $hour\:$min\:$sec";

    and the value of $year was grabbed via:

    ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)
    = localtime(time);

    To understand how a Perl function such as localtime() works, you'd
    better study its documentation:

    http://www.perldoc.com/perl5.8.0/pod/func/localtime.html

    That should give you what you need to solve the problem.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Nov 19, 2003
    #6
  7. warpman <> wrote:

    > Subject: Need some help...



    Please put the subject of your article in the Subject of your article.


    > This sub keeps on given me the following date:
    >
    > November 5, 103 at 10:16:33:
    >
    > I don't understand why it keeps on given me the year as 1xx instead of
    > 2 digits.



    Are you really using four year old code?

    It is pretty late in the game for fixing y2k problems...


    > ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
    > localtime(time);



    You should read the documentation for the functions that you use:

    perldoc -f localtime

    Note that the $year element is not simply the last
    two digits of the year. If you assume it is, then
    you create non-Y2K-compliant programs--and you
    wouldn't want to do that, would you?

    The proper way to get a complete 4-digit year is
    simply:

    $year += 1900;

    And to get the last two digits of the year (e.g.,
    '01' in 2001) do:

    ...


    > if ($sec < 10) {
    > $sec = "0$sec";
    > }



    This code is worth what you paid for it (or less).


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Nov 19, 2003
    #7
  8. warpman <> wrote:
    > I need some help. I'm new to perl and I have borrow the following
    > code. This sub keeps on given me the following date:
    >
    > November 5, 103 at 10:16:33:

    [...]

    Put this line at top of your script:
    use POSIX qw(strftime);

    Then, replace all the stuff below with these 3 lines:

    my @now = localtime;
    $date = strftime(($use_time ? '%T ' : '') . '%m/%d/%Y', @now);
    $long_date = strftime('%B %e, %Y at %T', @now);


    Read up on chomp() in place of your "chop() if ...";


    > ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
    > localtime(time);
    >
    > if ($sec < 10) {
    > $sec = "0$sec";
    > }
    > if ($min < 10) {
    > $min = "0$min";
    > }
    > if ($hour < 10) {
    > $hour = "0$hour";
    > }
    > if ($mon < 10) {
    > $mon = "0$mon";
    > }
    > if ($mday < 10) {
    > $mday = "0$mday";
    > }
    >
    > $month = ($mon + 1);
    >
    > @months = ("January","February","March","April","May","June","July","August","September","October","November","December");
    >
    > if ($use_time == 1) {
    > $date = "$hour\:$min\:$sec $month/$mday/$year";
    > }
    > else {
    > $date = "$month/$mday/$year";
    > }
    > chop($date) if ($date =~ /\n$/);
    >
    > $long_date = "$months[$mon] $mday, $year at $hour\:$min\:$sec";
    > # $long_date = "$months[$mon] $mday, 19$year at $hour\:$min\:$sec";
    > }



    --
    Glenn Jackman
    NCF Sysadmin
     
    Glenn Jackman, Nov 19, 2003
    #8
  9. Desmond Coughlan wrote:
    > Gunnar Hjalmarsson <> wrote ...
    >>You should not use fragments of other people's code if you don't
    >>understand how it works!

    >
    > Are you sure about that ? It'd mean that I'd use others' code ... erm ...
    > never.


    Well, I said *fragments of* ... I meant to distinguish between using
    a module, which is a complete whole intended to be used by others, and
    just copying a fragment of code from somewhere.

    Sorry if I was unclear.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Nov 19, 2003
    #9
  10. warpman

    Ben Morrow Guest

    Desmond Coughlan <> wrote:
    > Gunnar Hjalmarsson <> wrote ...
    > > You should not use fragments of other people's code if you don't
    > > understand how it works!

    >
    > Are you sure about that ? It'd mean that I'd use others' code ... erm ...
    > never.


    Absolutely!

    Note there is an important difference between copy/pasting other
    people's code and writing to a documented API. The API is what
    relieves you of the responsibility to understand what is going on
    and places it on the maintainer.

    Ben

    --
    I've seen things you people wouldn't believe: attack ships on fire off the
    shoulder of Orion; I've watched C-beams glitter in the darkness near the
    Tannhauser Gate. All these moments will be lost, in time, like tears in rain.
    Time to die. |-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-|
     
    Ben Morrow, Nov 19, 2003
    #10
  11. warpman <> wrote:

    > sub get_variables {
    >
    > if ($FORM{'followup'}) {
    > $followup = "1";
    > @followup_num = split(/,/,$FORM{'followup'});
    > $num_followups = @followups = @followup_num;
    > $last_message = pop(@followups);
    > $origdate = "$FORM{'origdate'}";
    > $origname = "$FORM{'origname'}";
    > $origsubject = "$FORM{'origsubject'}";
    > }

    [snip rest of code]

    Looks familiar. Checking... yup, it's code from WWWBoard from Matt's
    Script Archive. Some better-quality replacements are available at
    http://nms-cgi.sourceforge.net/.

    If you're trying to learn Perl, please don't use Matt's scripts as a
    model. If you search the Google usenet archive* you'll find plenty of
    past discussions on why this code is so reviled.

    * http://groups.google.com/

    --
    David Wall
     
    David K. Wall, Nov 20, 2003
    #11
  12. warpman

    Anno Siegel Guest

    Desmond Coughlan <> wrote in comp.lang.perl.misc:

    > I mean, come on: I _know_ Perl, damnit !!


    Few people would claim that without qualification.

    Anno
     
    Anno Siegel, Nov 21, 2003
    #12
  13. Anno Siegel <-berlin.de> wrote:

    > Desmond Coughlan <> wrote in
    > comp.lang.perl.misc:
    >
    >> I mean, come on: I _know_ Perl, damnit !!

    >
    > Few people would claim that without qualification.


    Maybe he means it in a Biblical sense. I've screwed around with Perl,
    and it has certainly screwed with my head at times.

    --
    David Wall
     
    David K. Wall, Nov 21, 2003
    #13
  14. warpman

    warpman Guest

    Hi Uri. Thanks for the info. I couldn't agree more about the code. Thanks again.

    Uri Guttman <> wrote in message news:<>...
    > put the subject in the subject of the post.
    >
    > did you steal/borrow/copy this code or create this mess yourself? it
    > looks like typical old cargo cult crap.
    >
    > this code is so perl4ish and so clunky.
    >
    > jeez, a y2k bug 3 years later.
    >
    > rtfm some more on localtime.
    >
    > no strict
    >
    > some unseen and probably bad cgi parser is used
    >
    > quoted scalar variables
    >
    > it is not worth fixing. dump it all and rewrite it.
    >
    > you should learn some perl from a better source too.
    >
    > uri
     
    warpman, Nov 21, 2003
    #14
  15. warpman

    warpman Guest

    I would like to thank all of you for your recommendations, suggestions
    and even criticism. Keep in mind that I'm new to PERL. I'm learning as
    I go. I took a look at the documentation and made some changes and
    everything seems to be going OK at the moment. Thanks again.


    (warpman) wrote in message news:<>...
    > I need some help. I'm new to perl and I have borrow the following
    > code. This sub keeps on given me the following date:
    >
    > November 5, 103 at 10:16:33:
    >
    > I don't understand why it keeps on given me the year as 1xx instead of
    > 2 digits. Any help would be greatly appreciated. Thanks in advanced.
    >
    >
    >
    > =====
    > sub get_variables {
    >
    > if ($FORM{'followup'}) {
    > $followup = "1";
    > @followup_num = split(/,/,$FORM{'followup'});
    > $num_followups = @followups = @followup_num;
    > $last_message = pop(@followups);
    > $origdate = "$FORM{'origdate'}";
    > $origname = "$FORM{'origname'}";
    > $origsubject = "$FORM{'origsubject'}";
    > }
    > else {
    > $followup = "0";
    > }
    >
    > if ($FORM{'name'}) {
    > $name = "$FORM{'name'}";
    > $name =~ s/"//g;
    > $name =~ s/<//g;
    > $name =~ s/>//g;
    > $name =~ s/\&//g;
    > }
    > else {
    > &error(no_name);
    > }
    >
    > if ($FORM{'email'} =~ /.*\@.*\..*/) {
    > $email = "$FORM{'email'}";
    > }
    >
    > if ($FORM{'subject'}) {
    > $subject = "$FORM{'subject'}";
    > $subject =~ s/\&/\&amp\;/g;
    > $subject =~ s/"/\&quot\;/g;
    > }
    > else {
    > &error(no_subject);
    > }
    >
    > if ($FORM{'url'} =~ /.*\:.*\..*/ && $FORM{'url_title'}) {
    > $message_url = "$FORM{'url'}";
    > $message_url_title = "$FORM{'url_title'}";
    > }
    >
    > if ($FORM{'img'} =~ /.*tp:\/\/.*\..*/) {
    > $message_img = "$FORM{'img'}";
    > }
    >
    > if ($FORM{'body'}) {
    > $body = "$FORM{'body'}";
    > $body =~ s/\cM//g;
    > $body =~ s/\n\n/<p>/g;
    > $body =~ s/\n/<br>/g;
    >
    > $body =~ s/&lt;/</g;
    > $body =~ s/&gt;/>/g;
    > $body =~ s/&quot;/"/g;
    > }
    > else {
    > &error(no_body);
    > }
    >
    > if ($quote_text == 1) {
    > $hidden_body = "$body";
    > $hidden_body =~ s/</&lt;/g;
    > $hidden_body =~ s/>/&gt;/g;
    > $hidden_body =~ s/"/&quot;/g;
    > }
    >
    > ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
    > localtime(time);
    >
    > if ($sec < 10) {
    > $sec = "0$sec";
    > }
    > if ($min < 10) {
    > $min = "0$min";
    > }
    > if ($hour < 10) {
    > $hour = "0$hour";
    > }
    > if ($mon < 10) {
    > $mon = "0$mon";
    > }
    > if ($mday < 10) {
    > $mday = "0$mday";
    > }
    >
    > $month = ($mon + 1);
    >
    > @months = ("January","February","March","April","May","June","July","August","September","October","November","December");
    >
    > if ($use_time == 1) {
    > $date = "$hour\:$min\:$sec $month/$mday/$year";
    > }
    > else {
    > $date = "$month/$mday/$year";
    > }
    > chop($date) if ($date =~ /\n$/);
    >
    > $long_date = "$months[$mon] $mday, $year at $hour\:$min\:$sec";
    > # $long_date = "$months[$mon] $mday, 19$year at $hour\:$min\:$sec";
    > }
     
    warpman, Nov 21, 2003
    #15
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest
    Replies:
    0
    Views:
    684
    Guest
    Feb 25, 2004
  2. Holmes!
    Replies:
    2
    Views:
    436
    Malcolm Dew-Jones
    Apr 2, 2005
  3. =?Utf-8?B?Q2hyaXM=?=

    Help Help. I really need some help with this

    =?Utf-8?B?Q2hyaXM=?=, Jan 31, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    568
    =?Utf-8?B?SmFzb24gVmVybWlsbGlvbg==?=
    Jan 31, 2007
  4. Domino
    Replies:
    5
    Views:
    385
    dorayme
    Nov 5, 2006
  5. Replies:
    4
    Views:
    339
    Puppet_Sock
    Oct 19, 2006
Loading...

Share This Page