what does underscore stands for ?

Discussion in 'Perl Misc' started by alpha_beta_release, Sep 11, 2006.

  1. HI

    what does underscore stands for ?
    e.g. get file modification time, someone write like this
    -M _

    what i understand is it's treated as bareword (filehandle and labels).
    Is it default filehandle, like $_ (for scalar)?
    or maybe i'm wrong. I need some explanation...

    Thanx in advance.
    alpha_beta_release, Sep 11, 2006
    #1
    1. Advertising

  2. ok. thanx. actually i've gone through this section, and forgot to
    mention about the solitary underscore ;) but what i need is the
    explanation about this special filehandle _. What it's purpose?

    Michele Dondi wrote:
    > On 10 Sep 2006 23:37:48 -0700, "alpha_beta_release"
    > <> wrote:
    >
    > >what does underscore stands for ?
    > >e.g. get file modification time, someone write like this
    > > -M _

    >
    > Check
    >
    > perldoc -f -X
    >
    > towards the end.
    >
    >
    > Michele
    > --
    > {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
    > (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
    > .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
    > 256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
    alpha_beta_release, Sep 11, 2006
    #2
    1. Advertising

  3. ok. i understand something.

    What i found is that if we provide this '_' to the second (and
    subsequent) file test operations (-M, -f etc), the result returned is
    from the first test operation. Am i correct?
    e.g.
    -f $somefile;
    -M _ ; # use the result of above operation

    -t $somefile; # fresh call
    -M _ ; # use the result of above operation

    Actually i found this in Dir::purge.pm, makes me wonder for while. It's
    no very clear at first. Anyway thanks Michele for the pointer.

    Michele Dondi wrote:
    > On 10 Sep 2006 23:37:48 -0700, "alpha_beta_release"
    > <> wrote:
    >
    > >what does underscore stands for ?
    > >e.g. get file modification time, someone write like this
    > > -M _

    >
    > Check
    >
    > perldoc -f -X
    >
    > towards the end.
    >
    >
    > Michele
    > --
    > {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
    > (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
    > .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
    > 256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
    alpha_beta_release, Sep 11, 2006
    #3
  4. alpha_beta_release wrote:
    > ok. i understand something.
    >
    > What i found is that if we provide this '_' to the second (and
    > subsequent) file test operations (-M, -f etc), the result returned is
    > from the first test operation. Am i correct?
    > e.g.
    > -f $somefile;
    > -M _ ; # use the result of above operation
    >
    > -t $somefile; # fresh call
    > -M _ ; # use the result of above operation


    It uses an _internal_ _intermediate_ result from the previous operation.

    When you do "-f $somefile", then the fact that $somefile is or is not a
    plain file does not appear out of thin air but the perl runtime has to
    perform a "stat" operation on $somefile which returns muchmuch more than
    just an indicator on the file type (see perldoc -f stat), so it is an
    optimization to keep the internal result of the internal stat operation
    for later reference.
    "-M _" will then not have to do a new "stat" but can just pick up the
    modification time from the data returned by the "stat" done for the "-f
    $somefile".

    HTH,
    --
    Josef Möllers (Pinguinpfleger bei FSC)
    If failure had no penalty success would not be a prize
    -- T. Pratchett
    Josef Moellers, Sep 11, 2006
    #4
  5. alpha_beta_release wrote:

    > -f $somefile;
    > -M _ ; # use the result of above operation


    > Actually i found this in Dir::purge.pm, makes me wonder for while. It's
    > no very clear at first. Anyway thanks Michele for the pointer.


    It's clear if you understand the idioms of Perl, and not if you don't,
    much the way casting to a function pointer looks like line noise in C
    unless you understand that this is a common idiom, recognize it and
    move on. The only difference is that Perl's idioms tend to hold more
    semantic weight in fewer symbols.

    _ in Perl is the sort of all-around tool meaning "default" or "supplied
    input". It has different contexts:

    _ - stat-operation default (last stat block)
    $_ - Default value stored to and read from by many operations. Also
    used as a temporary
    @_ - Parameter list to a subroutine

    Personally, I've always thought _ should also be a label, such that
    "next _" would always select the outermost loop, similar to the way
    "next" without a parameter selects the innermost.
    Aaron Sherman, Sep 11, 2006
    #5
    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. Maaxx
    Replies:
    4
    Views:
    1,618
    Bruce Lewis
    Feb 8, 2005
  2. hoox2
    Replies:
    6
    Views:
    376
    hoox2
    Oct 7, 2003
  3. dreamcatcher

    what strspn and strpbrk stands for ?

    dreamcatcher, Sep 19, 2003, in forum: C Programming
    Replies:
    9
    Views:
    1,239
    Dan Pop
    Sep 23, 2003
  4. Guy

    Swing stands for what?

    Guy, Jan 11, 2007, in forum: Java
    Replies:
    5
    Views:
    2,792
    Andrew Thompson
    Jan 12, 2007
  5. Tim Prince

    in strspn(): what "spn" stands for?

    Tim Prince, May 27, 2008, in forum: C Programming
    Replies:
    5
    Views:
    627
Loading...

Share This Page