shiqi
asked on
How come localtime() cannot work?
I am new to perl. Can anybody tell me how come my following script
cannot work? I am using perl on HP-UX 10.20.
#!/bin/perl
$newtime = localtime (time + 10*60 );
print ("New time is:$newtime");
#
When I run it , it doesn't show what the new time is, Why?
New Response on 14/02/00:
I have tried all you recommended but still got nothing came out when I run it. It seems localtime()
does not work at all on my system. Do I need to link to any additional perl libraries before I run it or
do I need to initialize $time before I call localtime() ?
New Response on 18/02/00:
What I see when key in your commands is shown as below,
# perl
$l=localtime();
print "+++$l+++\n";
++++++
#
New Response on 19/02/00:
I got the following when running "perl -v"
# perl -v
This is perl, version 4.0
$RCSfile: perl.c,v $$Revision: 4.0.1.8 $$Date: 1993/02/05 19:39:30 $
Patch level: 36
Copyright (c) 1989, 1990, 1991, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 4.0 source kit.
#
cannot work? I am using perl on HP-UX 10.20.
#!/bin/perl
$newtime = localtime (time + 10*60 );
print ("New time is:$newtime");
#
When I run it , it doesn't show what the new time is, Why?
New Response on 14/02/00:
I have tried all you recommended but still got nothing came out when I run it. It seems localtime()
does not work at all on my system. Do I need to link to any additional perl libraries before I run it or
do I need to initialize $time before I call localtime() ?
New Response on 18/02/00:
What I see when key in your commands is shown as below,
# perl
$l=localtime();
print "+++$l+++\n";
++++++
#
New Response on 19/02/00:
I got the following when running "perl -v"
# perl -v
This is perl, version 4.0
$RCSfile: perl.c,v $$Revision: 4.0.1.8 $$Date: 1993/02/05 19:39:30 $
Patch level: 36
Copyright (c) 1989, 1990, 1991, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 4.0 source kit.
#
shigi,
i tried you program and it worked fine.
i would suggest you do this,
At the command prompt type which perl and press enter.
this will show you the full path to the perl binary.
let say its /usr/local/bin/ then,
change your script to.
#!/usr/local/bin/perl
$newtime = localtime (time + 10*60 );
print ("New time is:$newtime");
i tried you program and it worked fine.
i would suggest you do this,
At the command prompt type which perl and press enter.
this will show you the full path to the perl binary.
let say its /usr/local/bin/ then,
change your script to.
#!/usr/local/bin/perl
$newtime = localtime (time + 10*60 );
print ("New time is:$newtime");
And change this line :
print ("New time is:$newtime");
to
print ("New time is:$newtime\n");
and it will magically work :-)
Tobias
print ("New time is:$newtime");
to
print ("New time is:$newtime\n");
and it will magically work :-)
Tobias
Also, you might want to try this. It's my whole time/date routine.
# ************************** ***** Get Date
sub get_date
{
my (@months,@days,$sec,$min,$ hour,$mday ,$mon,$yea r,$wday,$y d,$mydate) ;
my @months = ('Janurary','Feburary','Ma rch','Apri l','May',' June','Jul y','August ','Septemb er','Octob er','Novem ber','Dece mber');
my @days = ('Sunday','Monday','Tuesda y','Wedsda y','Thursd ay','Frida y','Saturd ay');
my ($sec,$min,$hour,$mday,$mo n,$year,$w day) = (localtime(time))[0,1,2,3, 4,5,6];
$year += 1900;
my $ampm = 'AM';
if (!$hour) { $hour = 12; }
elsif ($hour > 12) { $ampm = 'PM'; $hour -= 12; }
elsif ($hour = 12) { $ampm = 'PM'; }
if ($min<10) {$min="0".$min; }
$mydate = " $days[$wday], $months[$mon] $mday, $year at $hour:$min $ampm";
}
# ************************** *** END SOURCE CODE
# **************************
sub get_date
{
my (@months,@days,$sec,$min,$
my @months = ('Janurary','Feburary','Ma
my @days = ('Sunday','Monday','Tuesda
my ($sec,$min,$hour,$mday,$mo
$year += 1900;
my $ampm = 'AM';
if (!$hour) { $hour = 12; }
elsif ($hour > 12) { $ampm = 'PM'; $hour -= 12; }
elsif ($hour = 12) { $ampm = 'PM'; }
if ($min<10) {$min="0".$min; }
$mydate = " $days[$wday], $months[$mon] $mday, $year at $hour:$min $ampm";
}
# **************************
ASKER
Edited text of question.
ASKER
Edited text of question.
ASKER
Edited text of question.
ASKER
Adjusted points to 50
shigi,
try the following and do exactly as I say:
Enter the following at your shell prompt ([ENTER] is the Return/enter key [CTRL-D] means pressing the control-key and the D key together):
perl [ENTER]
$l=localtime(); [ENTER]
print "+++$l+++\n"; [ENTER]
[CTRL-D]
What do you see?
try the following and do exactly as I say:
Enter the following at your shell prompt ([ENTER] is the Return/enter key [CTRL-D] means pressing the control-key and the D key together):
perl [ENTER]
$l=localtime(); [ENTER]
print "+++$l+++\n"; [ENTER]
[CTRL-D]
What do you see?
ASKER
Edited text of question.
If you type:
perl -v
what do you see?
perl -v
what do you see?
ASKER
Edited text of question.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
shigi,
and you may even have a perl5 executable and just don't know about it. try executing "perl5" instead of "perl". Or look for the location where "perl" is installed ('which perl' could work) and look for other perl* executables with newer dates.
Tobias
and you may even have a perl5 executable and just don't know about it. try executing "perl5" instead of "perl". Or look for the location where "perl" is installed ('which perl' could work) and look for other perl* executables with newer dates.
Tobias
ASKER
No. There is no perl5 on my machine.
Where can I get perl5 for HP-UX 10.20 ?
Where can I get perl5 for HP-UX 10.20 ?
shigi,
try http://hpux.cae.wisc.edu/ and specifically http://hpux.cae.wisc.edu/hppd/hpux/Languages/perl-5.005_03/
But you should really try to compile it yourself :-)
Tobias
try http://hpux.cae.wisc.edu/ and specifically http://hpux.cae.wisc.edu/hppd/hpux/Languages/perl-5.005_03/
But you should really try to compile it yourself :-)
Tobias
This line (#!/bin/perl ). I have never seen this variation... though it could be. What if you do this:
#!/bin/perl
$time = time + 10*60;
$newtime = localtime ($time);
print ("New time is:$newtime");
A stupid change but to give something. Both worked for me so I'm not really sure...?