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

R

rlf

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]
 
P

Peter Makholm

rlf said:
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
 
R

rlf

Quoth Don Piven said:
rlf said:
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.
 
N

Nathan Keel

rlf said:
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.
 
U

Uri Guttman

NK> rlf said:
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
 
N

Nathan Keel

Uri said:
NK> rlf said:
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.
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.
 
U

Uri Guttman

NK> Uri Guttman said:
"NK" == Nathan Keel <[email protected]> writes:
NK> rlf said:
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.

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!
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
 
N

Nathan Keel

Uri said:
NK> Uri Guttman said:
NK> rlf said:
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?
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.
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.
nal cake.
 
U

Uri Guttman

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
 
N

Nathan Keel

Uri said:
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.
 
U

Uri Guttman

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

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,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top