Why does "$v = @ARGV[0]" work ?

Discussion in 'Perl Misc' started by rlf, Sep 5, 2009.

  1. rlf

    rlf Guest

    I've taken over some perl code that starts out with :

    $v = @ARGV[0]

    That's an @ sign on ARGV, not a dollar sign.

    This seems to get the first element OK, but I don' know why. I've
    never seen this construct used before, and I cannot find a parser rule
    that says that you could use EITHER a $ or @ in this context.

    Am curious to know why the result of this parse gets the same action
    as taking the scalar with

    $v = $ARGV[0]
     
    rlf, Sep 5, 2009
    #1
    1. Advertising

  2. rlf <> writes:

    > I've taken over some perl code that starts out with :
    >
    > $v = @ARGV[0]
    >
    > That's an @ sign on ARGV, not a dollar sign.


    @ARGV[0] makes an array slice with a single element. It is explained
    in 'perldoc perldata' (look for the heading 'Slices'). I'm not really
    sure if a single element slice has any usable function, but they are
    allowed.

    //Makholm
     
    Peter Makholm, Sep 5, 2009
    #2
    1. Advertising

  3. rlf

    rlf Guest

    On 5 Sep, 10:42, Ben Morrow <> wrote:
    > Quoth Don Piven <>:
    >
    > > rlf wrote:
    > > > I've taken over some perl code that starts out with :

    >
    > > > $v = @ARGV[0]

    >
    > > > That's an @ sign on ARGV, not a dollar sign.

    >
    > > > This seems to get the first element OK, but I don' know why. I've
    > > > never seen this construct used before, and I cannot find a parser rule
    > > > that says that you could use EITHER a $ or @ in this context.

    >
    > It's worth noting that 'use warnings' will warn about this. If you have
    > inherited some code with dodgy coding standards, my recommendation would
    > be to start by adding
    >
    >     use strict;
    >     use warnings;
    >
    > at the top and fixing all the resultant diagnostics.
    >
    > <snip>
    >
    >
    >
    > > @ARGV[0] is a one-element slice out of the @ARGV array, which is then
    > > used as a list constructor for the assignment.  Now, man perldata says
    > > that "[in] a context not requiring a list value, the value of what
    > > appears to be a list literal is simply the value of the final element",
    > > working the same as C's and Perl's comma operator.  More generally,
    > > evaluating a list constructor in scalar context yields you that
    > > last-element behavior, while evaluating a list VARIABLE

    >
    > An array. The difference between list and array is important.
    >
    > > in scalar
    > > context gets you the length of the list.

    >
    > Ben


    Thank you all for the clarification.
     
    rlf, Sep 6, 2009
    #3
  4. rlf

    Nathan Keel Guest

    rlf wrote:

    > I've taken over some perl code that starts out with :
    >
    > $v = @ARGV[0]
    >
    > That's an @ sign on ARGV, not a dollar sign.


    It's called a slice. [0] is the first element. Not the ideal way to
    write it.
     
    Nathan Keel, Sep 7, 2009
    #4
  5. rlf

    Uri Guttman Guest

    >>>>> "NK" == Nathan Keel <> writes:

    NK> rlf wrote:
    >> I've taken over some perl code that starts out with :
    >>
    >> $v = @ARGV[0]
    >>
    >> That's an @ sign on ARGV, not a dollar sign.


    NK> It's called a slice. [0] is the first element. Not the ideal way to
    NK> write it.

    how helpful. at least tell him how to do it correctly. oh, you don't
    help, you just snark on those who do. and it was already correctly
    answered 2 days ago.

    uri

    --
    Uri Guttman ------ -------- http://www.sysarch.com --
    ----- Perl Code Review , Architecture, Development, Training, Support ------
    --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
     
    Uri Guttman, Sep 7, 2009
    #5
  6. rlf

    Nathan Keel Guest

    Uri Guttman wrote:

    >>>>>> "NK" == Nathan Keel <> writes:

    >
    > NK> rlf wrote:
    > >> I've taken over some perl code that starts out with :
    > >>
    > >> $v = @ARGV[0]
    > >>
    > >> That's an @ sign on ARGV, not a dollar sign.

    >
    > NK> It's called a slice. [0] is the first element. Not the ideal
    > way to NK> write it.
    >
    > how helpful. at least tell him how to do it correctly.


    Good thing you offered your "help" with _your_ "snarky" remark. You are
    still a dick, I see.

    > oh, you don't
    > help, you just snark on those who do.


    I did no such thing.

    > and it was already correctly
    > answered 2 days ago.


    So what? I don't have my news reader set the same way you do, and a lot
    of people don't, which is why there are usually multiple replies to the
    same question. Of course, you "have it out" for me (because I don't
    put up with your ego bullshit here), so you'd only try and call me on
    the same thing everyone else does (including you). What a weak debater
    you are.

    > uri

    nal cake.

    Uri, at least write your own name as a proper noun, if you want to think
    you're as smart as you actually aren't. Now, **** off, troll boy.
     
    Nathan Keel, Sep 8, 2009
    #6
  7. rlf

    Uri Guttman Guest

    >>>>> "NK" == Nathan Keel <> writes:

    NK> Uri Guttman wrote:
    >>>>>>> "NK" == Nathan Keel <> writes:

    >>

    NK> rlf wrote:
    >> >> I've taken over some perl code that starts out with :
    >> >>
    >> >> $v = @ARGV[0]
    >> >>
    >> >> That's an @ sign on ARGV, not a dollar sign.

    >>

    NK> It's called a slice. [0] is the first element. Not the ideal
    >> way to NK> write it.
    >>
    >> how helpful. at least tell him how to do it correctly.


    NK> Good thing you offered your "help" with _your_ "snarky" remark. You are
    NK> still a dick, I see.

    nope, i saw the correct answers and didn't need to add more. you added a
    useless answer. and you still can't refrain from vulgarity. your momma
    didn't raise you too well.

    >> and it was already correctly
    >> answered 2 days ago.


    NK> So what? I don't have my news reader set the same way you do, and a lot
    NK> of people don't, which is why there are usually multiple replies to the
    NK> same question. Of course, you "have it out" for me (because I don't
    NK> put up with your ego bullshit here), so you'd only try and call me on
    NK> the same thing everyone else does (including you). What a weak debater
    NK> you are.

    2 days is long even on usenet time. but you don't care about helping as
    we have seen. snark away!

    >> uri

    NK> nal cake.

    how high school of you. now grow up and graduate kindergarten already.

    NK> Uri, at least write your own name as a proper noun, if you want to think
    NK> you're as smart as you actually aren't. Now, **** off, troll boy.

    you don't even know what my name means, its origins or history. snarky
    snark snark.

    as for brains, your low educational tone and repeated use of the same
    kiddie insults settles the matter in your case. the best punishment for
    you is being you.

    uri

    --
    Uri Guttman ------ -------- http://www.sysarch.com --
    ----- Perl Code Review , Architecture, Development, Training, Support ------
    --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
     
    Uri Guttman, Sep 8, 2009
    #7
  8. rlf

    Nathan Keel Guest

    Uri Guttman wrote:

    >>>>>> "NK" == Nathan Keel <> writes:

    >
    > NK> Uri Guttman wrote:
    > >>>>>>> "NK" == Nathan Keel <> writes:
    > >>

    > NK> rlf wrote:
    > >> >> I've taken over some perl code that starts out with :
    > >> >>
    > >> >> $v = @ARGV[0]
    > >> >>
    > >> >> That's an @ sign on ARGV, not a dollar sign.
    > >>

    > NK> It's called a slice. [0] is the first element. Not the ideal
    > >> way to NK> write it.
    > >>
    > >> how helpful. at least tell him how to do it correctly.

    >
    > NK> Good thing you offered your "help" with _your_ "snarky" remark.
    > You are NK> still a dick, I see.
    >
    > nope, i saw the correct answers and didn't need to add more.


    Perhaps in this case you did so, but in a lot of threads you do not.
    Like I said, I don't have the posts show the same way you do, and so
    what? Why don't you give grief to everyone else that also reply to all
    of the threads here daily, even after other people do? Why? Because
    you're just flipped out that I didn't put up with your ego bullshit in
    another thread a while ago. You're just an arrogant worm and you need
    to get over it.

    > you added
    > a useless answer.


    It wasn't useless. You are useless. Do you think your arrogant attacks
    on people are helpful? Or more helpful than a redundant answer? You
    actually probably do think your arrogant, pointless and unhelpful and
    uncivil interactions are more purposeful. Sad.

    > and you still can't refrain from vulgarity.


    Not when you're acting like a worthless prick. Treat people with
    civility and you'll find you get a different reaction.

    > your
    > momma didn't raise you too well.


    And apparently yours did a great job with how arrogant and bullyish you
    try and be?

    > >> and it was already correctly
    > >> answered 2 days ago.

    >
    > NK> So what? I don't have my news reader set the same way you do,
    > and a lot NK> of people don't, which is why there are usually
    > multiple replies to the
    > NK> same question. Of course, you "have it out" for me (because I
    > don't NK> put up with your ego bullshit here), so you'd only try and
    > call me on
    > NK> the same thing everyone else does (including you). What a weak
    > debater NK> you are.
    >
    > 2 days is long even on usenet time.


    Irrelevant.

    > but you don't care about helping
    > as we have seen. snark away!


    I can say the same about you. You are more interested in attacking
    people with your snarky arrogance. Grow up.

    > >> uri

    > NK> nal cake.
    >
    > how high school of you.


    Well, that's pretty much about the value I place on you, to be honest.

    > now grow up and graduate kindergarten already.


    Yeah, because _you_ are acting real mature yourself there, buddy.
    Sadly, you really think you don't have to follow your own advice.
    You've got serious emotional problems to think your own rules don't
    apply to you and that you can try and bully people on "usenet" of all
    places. What a fucking coward and a clown you are.

    > NK> Uri, at least write your own name as a proper noun, if you want
    > to think
    > NK> you're as smart as you actually aren't. Now, **** off, troll
    > boy.
    >
    > you don't even know what my name means, its origins or history. snarky
    > snark snark.


    I actually do (and really, what difference would it make if I didn't?),
    and it's a proper noun, so what I said still applies. Honestly, you
    think you aren't snarky? You're acting like a complete bitch on this
    group all of the time.

    > as for brains, your low educational tone and repeated use of the same
    > kiddie insults settles the matter in your case.


    Yes, I know you think that whatever you "proclaim" about people you
    personally decided to have a problem with, somehow makes it a "fact" to
    your arrogant mind. This is not surprising. You are irrelevant and
    stupid.

    > the best punishment
    > for you is being you.


    Funny, I was just thinking the same thing about you. Now, if only you
    could practice what you preach, you'd maybe not come off looking like a
    completely arrogant asshole without any class. And be honest, before I
    ever referred to you in the accurately portrayed vulgar term(s), you
    were already pulling and saying this same bullshit anyway. You can't
    be friendly, because you're that much of a prick. You're just going to
    have to deal with the fact that you can't "push" me around on usenet,
    and how cowardly are you anyway? Go back to your bubble, you fucking
    fruitcake.

    > uri

    nal cake.
     
    Nathan Keel, Sep 8, 2009
    #8
  9. rlf

    Nathan Keel Guest

    Uri Guttman wrote:

    >
    > uri


    PS: Congrats on making yet another thread all about you, Uri. What a
    trooper you are!
     
    Nathan Keel, Sep 8, 2009
    #9
  10. rlf

    Uri Guttman Guest

    >>>>> "NK" == Nathan Keel <> writes:

    NK> Uri Guttman wrote:
    >>
    >> uri


    NK> PS: Congrats on making yet another thread all about you, Uri. What a
    NK> trooper you are!

    pot meet kettle. you started it! nyah nyah nyah!! so's your old man!
    your momma codes in python!! your sister is a lisper!!

    uri

    --
    Uri Guttman ------ -------- http://www.sysarch.com --
    ----- Perl Code Review , Architecture, Development, Training, Support ------
    --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
     
    Uri Guttman, Sep 8, 2009
    #10
  11. rlf

    Nathan Keel Guest

    Uri Guttman wrote:

    >>>>>> "NK" == Nathan Keel <> writes:

    >
    > NK> Uri Guttman wrote:
    > >>
    > >> uri

    >
    > NK> PS: Congrats on making yet another thread all about you, Uri.
    > What a NK> trooper you are!
    >
    > pot meet kettle.


    You think? Wow, I have all sorts of "emotional ailments" for not
    putting up with your arrogant bullshit. You make me laugh. You think
    this BS is contributing? I posted a response to the OP, I stated it
    was a slice and not the best way to do it (they asked what it was).
    You reply attacking me and you think that I am the problem?

    > you started it! nyah nyah nyah!!


    What a retard you are. I can't tell if you were saying I said "you"
    "started it", or if you were saying I did (but I didn't, if you want to
    make that claim) Your English is awful, and so is your attitude. You
    might not like me because I don't think you're anyone special, but your
    actions here are going to just annoy other members of the group. If I
    attack you and you defend yourself, that's one thing, but I've not
    interacted with you in a while. You're just a worthless person, you
    should end your life.

    > so's your old man!


    Pardon? Your grammar is atrocious, and it's difficult to parse what
    you're saying. Anyway, your attitude is misplaced. You can't fault
    someone simply because they didn't allow you to push them around...
    well, maybe YOU can (and do). Get a life or find a better reason to
    make an "enemy" of someone you don't even know.

    > your momma codes in python!! your sister is a lisper!!


    Okay.

    > uri

    nal cake.

    You're such a coward.
     
    Nathan Keel, Sep 8, 2009
    #11
  12. rlf

    Uri Guttman Guest

    >>>>> "NK" == Nathan Keel <> writes:

    NK> Uri Guttman wrote:
    >>>>>>> "NK" == Nathan Keel <> writes:

    >>

    NK> Uri Guttman wrote:
    >> >>
    >> >> uri

    >>

    NK> PS: Congrats on making yet another thread all about you, Uri.
    >> What a NK> trooper you are!
    >>
    >> pot meet kettle.


    NK> You think? Wow, I have all sorts of "emotional ailments" for not
    NK> putting up with your arrogant bullshit. You make me laugh. You think
    NK> this BS is contributing? I posted a response to the OP, I stated it
    NK> was a slice and not the best way to do it (they asked what it was).
    NK> You reply attacking me and you think that I am the problem?

    your answer was useless. you seem to think you are helping others. that
    is the core issue. stop thinking you are helping. you don't know perl
    nor how to teach it.

    >> uri

    NK> nal cake.

    NK> You're such a coward.

    coward? hehe. show some of your code for review. check out mine and
    slash away. cowardice is commenting without showing work. you don't know
    from code nor perl.

    uri

    --
    Uri Guttman ------ -------- http://www.sysarch.com --
    ----- Perl Code Review , Architecture, Development, Training, Support ------
    --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
     
    Uri Guttman, Sep 8, 2009
    #12
  13. rlf

    Nathan Keel Guest

    Uri Guttman wrote:

    > your answer was useless.


    Ugh, *you* are useless. Move on and bug someone else.
     
    Nathan Keel, Sep 9, 2009
    #13
    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. =?ISO-8859-1?Q?Thomas_N=FCcker?=

    sys.argv[0] - 'module' object has no attribute 'argv'

    =?ISO-8859-1?Q?Thomas_N=FCcker?=, Jun 30, 2003, in forum: Python
    Replies:
    0
    Views:
    935
    =?ISO-8859-1?Q?Thomas_N=FCcker?=
    Jun 30, 2003
  2. jblazi
    Replies:
    5
    Views:
    447
    jblazi
    Aug 16, 2004
  3. Horace Nunley

    why why why does function not work

    Horace Nunley, Sep 27, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    470
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Sep 27, 2006
  4. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    921
    Mark Rae
    Dec 21, 2006
  5. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,073
    Smokey Grindel
    Dec 2, 2006
Loading...

Share This Page