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.
#
shiqiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

guadalupeCommented:
What about the shebang...?

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...?
0
maneshrCommented:
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");
0
thoellriCommented:
And change this line :

  print ("New time is:$newtime");

to

  print ("New time is:$newtime\n");

and it will magically work :-)

  Tobias
0
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

jgoreCommented:
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,$year,$wday,$yd,$mydate);

my @months = ('Janurary','Feburary','March','April','May','June','July','August','September','October','November','December');

my @days = ('Sunday','Monday','Tuesday','Wedsday','Thursday','Friday','Saturday');

my ($sec,$min,$hour,$mday,$mon,$year,$wday) = (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
0
shiqiAuthor Commented:
Edited text of question.
0
shiqiAuthor Commented:
Edited text of question.
0
shiqiAuthor Commented:
Edited text of question.
0
shiqiAuthor Commented:
Adjusted points to 50
0
thoellriCommented:
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?
0
shiqiAuthor Commented:
Edited text of question.
0
ozoCommented:
If you type:
 
  perl -v

what do you see?
0
shiqiAuthor Commented:
Edited text of question.
0
ozoCommented:
Perl4, has been obsolete for several years now.
You really should upgrade to Perl5.
localtime in perl4 could only return an array, not a scalar.
But if you must use an archaic verson of perl, jgore's routine could work in perl4 if you remove the 'my's
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
thoellriCommented:
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
0
shiqiAuthor Commented:
No. There is no perl5 on my machine.
 Where can I get perl5 for HP-UX 10.20 ?
0
thoellriCommented:
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

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.