print scalar localtime

Discussion in 'Perl Misc' started by Rahul, Jan 29, 2004.

  1. Rahul

    Rahul Guest

    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.
    Rahul, Jan 29, 2004
    #1
    1. Advertising

  2. Rahul

    kz Guest

    "Rahul" <> wrote in message
    news:9f9Sb.7968$...
    > 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
    kz, Jan 29, 2004
    #2
    1. Advertising

  3. 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
    John W. Krahn, Jan 29, 2004
    #3
  4. Rahul

    kz Guest

    "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
    kz, Jan 29, 2004
    #4
  5. Rahul

    Guest

    "Rahul" <> wrote:
    > 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

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service New Rate! $9.95/Month 50GB
    , Jan 29, 2004
    #5
  6. Rahul

    Uri Guttman Guest

    >>>>> "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
    Uri Guttman, Jan 29, 2004
    #6
  7. Rahul

    Joe Smith Guest

    kz wrote:

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


    perldoc -f wantarray
    -Joe
    Joe Smith, Feb 1, 2004
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. keto
    Replies:
    0
    Views:
    936
  2. Clint Olsen
    Replies:
    6
    Views:
    360
    Jeff 'japhy' Pinyan
    Nov 13, 2003
  3. Ian Wilson

    list vs scalar context for localtime?

    Ian Wilson, Oct 25, 2004, in forum: Perl Misc
    Replies:
    5
    Views:
    122
    Uri Guttman
    Oct 26, 2004
  4. Mark

    Replace scalar in another scalar

    Mark, Jan 27, 2005, in forum: Perl Misc
    Replies:
    4
    Views:
    163
    Arndt Jonasson
    Jan 27, 2005
  5. cartercc
    Replies:
    29
    Views:
    208
    Joost Diepenmaat
    Feb 26, 2009
Loading...

Share This Page