-1

I printed the localtime return values without storing that into one variable, it is display some digits I don't know what is that, but if we use that return value in localtime and store that into scalar variable it is displaying some date format.

for example

print localtime,"\n";

its print output

713156411531250

then I give that output to arguments of localtime like

$time=localtime(713156411531250);
print "$time\n";

Output:

Sat Jan 14 16:37:30 22600997
Karthikeyan.R.S
  • 3,991
  • 1
  • 19
  • 31
Rajalakshmi
  • 681
  • 5
  • 17
  • Perhaps you could try reading [the documentation for the localtime function](http://perldoc.perl.org/functions/localtime.html). – Dave Cross May 11 '15 at 12:11

1 Answers1

2

Perl in general, and localtime specifically is magic - it knows in what context it's being used.

So you can use things like wantarray() within a sub to detect whether the caller is expecting multiple results.

localtime is much the same.

If you 'use' it in a LIST context, it returns a list of values:

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

You are effectively doing this by 'just' printing it.

E.g.

print scalar localtime,"\n";
print join ( " ", localtime );

Gives:

Fri May  8 11:20:15 2015
15 20 11 8 4 115 5 127 1
Sobrique
  • 52,974
  • 7
  • 60
  • 101
  • if we give only `print localtime` what time it is return? – Rajalakshmi May 08 '15 at 10:27
  • @Rajalakshmi it doesn't return a time; because you are calling it where a list is expected, it returns a list of sec, min, hour, and so on and you print them all joined together. don't do that. – ysth May 08 '15 at 10:29
  • It returns list of date parts => `print join " ", localtime;` – mpapec May 08 '15 at 10:29
  • @Сухой27 I know that if we give only local time its give current date and time but in print its not do like this – Rajalakshmi May 08 '15 at 10:33
  • 1
    `print` is doing things in a list context. You are basically doing: `my @stuff = localtime(); print @stuff`. E.g. printing the resultant array. That's so you can `print function(),$variable,"\n";` - you're passing it a list when you do that. – Sobrique May 08 '15 at 10:35