print scalar localtime

R

Rahul

Hi ,
Sorry if this pisses of someone
But

When I say "print scalar localtime" I get the result as Thu Jan 29 16:59:52
2004
now if I remove scalar I get 210172901044280.

The result are as expected,

my question is How does adding "Scalar" changes the format of localtime.
 
K

kz

Rahul said:
Hi ,
Sorry if this pisses of someone
But

When I say "print scalar localtime" I get the result as Thu Jan 29 16:59:52
2004
now if I remove scalar I get 210172901044280.

The result are as expected,

my question is How does adding "Scalar" changes the format of localtime.
perldoc -f localtime

<quote>
In scalar context, "localtime()" returns the ctime(3) value:
$now_string = localtime; # e.g., "Thu Oct 13 04:54:34 1994"
</quote>

HTH,

Zoltan
 
J

John W. Krahn

Rahul said:
When I say "print scalar localtime" I get the result as Thu Jan 29 16:59:52
2004
now if I remove scalar I get 210172901044280.

The result are as expected,

my question is How does adding "Scalar" changes the format of localtime.

Because localtime returns a scalar in scalar context and a list in list
context and since print forces a list context you need to insert
"scalar" to force a scalar context.


John
 
K

kz

[snip]
Because localtime returns a scalar in scalar context and a list in list
context and since print forces a list context you need to insert
"scalar" to force a scalar context.

John,

Is "ref" THE (best) way to check the context of an expression, like this:

if (ref($r) eq "sometype") {
print "r is a reference to sometype.\n";
}

Regards,

Zoltan
 
C

ctcgag

Rahul said:
Hi ,
Sorry if this pisses of someone
But

When I say "print scalar localtime" I get the result as Thu Jan 29
16:59:52 2004
now if I remove scalar I get 210172901044280.

The result are as expected,

my question is How does adding "Scalar" changes the format of localtime.

Through wantarray, or some internal equivalent of it.

Xho
 
U

Uri Guttman

k> Is "ref" THE (best) way to check the context of an expression, like this:

k> if (ref($r) eq "sometype") {
k> print "r is a reference to sometype.\n";
k> }

huh? where is the context checked there? do you have a basic
understanding of list vs scalar context? the code AROUND or NEAR an
expression provides the context, not the expression itself. you can't
directly check the context inside an expression but you don't need to,
you just look at the code and you can see what context is provided. but
there is a way to do so inside a sub and that is with wantarray.

uri
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top