Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > print scalar localtime

Reply
Thread Tools

print scalar localtime

 
 
Rahul
Guest
Posts: n/a
 
      01-29-2004
Hi ,
Sorry if this ****es 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.


 
Reply With Quote
 
 
 
 
kz
Guest
Posts: n/a
 
      01-29-2004
"Rahul" <> wrote in message
news:9f9Sb.7968$...
> Hi ,
> Sorry if this ****es 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


 
Reply With Quote
 
 
 
 
John W. Krahn
Guest
Posts: n/a
 
      01-29-2004
Rahul wrote:
>
> 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
--
use Perl;
program
fulfillment
 
Reply With Quote
 
kz
Guest
Posts: n/a
 
      01-29-2004
"John W. Krahn" <> wrote in message
news:...

[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


 
Reply With Quote
 
ctcgag@hotmail.com
Guest
Posts: n/a
 
      01-29-2004
"Rahul" <> wrote:
> Hi ,
> Sorry if this ****es 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

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service New Rate! $9.95/Month 50GB
 
Reply With Quote
 
Uri Guttman
Guest
Posts: n/a
 
      01-29-2004
>>>>> "k" == kz <> writes:

k> "John W. Krahn" <> wrote in message
k> news:...

>> 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.


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

--
Uri Guttman ------ -------- 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
 
Joe Smith
Guest
Posts: n/a
 
      02-01-2004
kz wrote:

> Is "ref" THE (best) way to check the context of an expression


perldoc -f wantarray
-Joe
 
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
how do I print the name and value of a scalar cartercc Perl Misc 29 02-26-2009 02:50 PM
Replace scalar in another scalar Mark Perl Misc 4 01-27-2005 02:48 PM
list vs scalar context for localtime? Ian Wilson Perl Misc 5 10-25-2004 11:33 PM
Converting for localtime() or gmtime() to time() Stephen Perl 1 05-19-2004 03:51 PM
Shorthand for($scalar) loops and resetting pos($scalar) Clint Olsen Perl Misc 6 11-13-2003 12:50 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57