Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Need some help...

Reply
Thread Tools

Need some help...

 
 
warpman
Guest
Posts: n/a
 
      11-19-2003
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,$isd st) =
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";
}
 
Reply With Quote
 
 
 
 
Xaonon
Guest
Posts: n/a
 
      11-19-2003
Ned i bach <(E-Mail Removed) >, warpman
<(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
Xaonon
Guest
Posts: n/a
 
      11-19-2003
Ned i bach <(E-Mail Removed) >, warpman
<(E-Mail Removed)> 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
 
Reply With Quote
 
Eric Schwartz
Guest
Posts: n/a
 
      11-19-2003
http://www.velocityreviews.com/forums/(E-Mail Removed) (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.
 
Reply With Quote
 
Uri Guttman
Guest
Posts: n/a
 
      11-19-2003

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 ------ (E-Mail Removed) -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
 
Reply With Quote
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      11-19-2003
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,$isd st)
= 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...localtime.html

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

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      11-19-2003
warpman <(E-Mail Removed)> 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,$isd st) =
> 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
(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
Glenn Jackman
Guest
Posts: n/a
 
      11-19-2003
warpman <(E-Mail Removed)> 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,$isd st) =
> 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
(E-Mail Removed)
 
Reply With Quote
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      11-19-2003
Desmond Coughlan wrote:
> Gunnar Hjalmarsson <(E-Mail Removed)> 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

 
Reply With Quote
 
Ben Morrow
Guest
Posts: n/a
 
      11-19-2003

Desmond Coughlan <(E-Mail Removed)> wrote:
> Gunnar Hjalmarsson <(E-Mail Removed)> 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. |-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-| (E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need some help fixing some HTML and CSS problems Domino HTML 5 11-05-2006 09:58 PM
Wanna make some dough? I need some FO docs created. Holmes! XML 2 04-02-2005 10:43 PM
Need some help for some perl homework.... Perl 0 02-25-2004 01:45 AM
Forms Authentication question: How to have some pages open and some requiring forms authentication Eric ASP .Net 2 02-13-2004 02:14 PM
Some questions regarding 070-305 and hopefully some right answers. Needs correction... wink, wink ;-) Daniel Walzenbach MCSD 1 11-10-2003 12:25 AM



Advertisments