short script differences

P

Peder Ydalus

What is the difference between the following scripts:

perl -e 'sub t { $a = @_; return $a; } $b = t(0, 1, 2); print "$b\n"'
perl -e 'sub t { ($a) = @_; return $a; } $b = t(0, 1, 2); print "$b\n"'
perl -e 'sub t { @a = @_; return @a; } $b = t(0, 1, 2); print "$b\n"'
 
A

A. Sinan Unur

What is the difference between the following scripts:

What happened when you tried them out?
perl -e 'sub t { $a = @_; return $a; } $b = t(0, 1, 2); print "$b\n"'

$a is set to the number of arguments t was called with.
perl -e 'sub t { ($a) = @_; return $a; } $b = t(0, 1, 2); print "$b\n"'

$a is set to the first argument passed to t.
perl -e 'sub t { @a = @_; return @a; } $b = t(0, 1, 2); print "$b\n"'

@a holds the arguments passed to t. $b set to the number of elements in @a.

Sinan.
 
P

Peder Ydalus

Thanks!
Just needed that to clear up something...
I was somewhat uncertain about the difference between 1 and 3.

- P -
 
J

Jürgen Exner

Peder said:
What is the difference between the following scripts:

perl -e 'sub t { $a = @_; return $a; } $b = t(0, 1, 2); print "$b\n"'
perl -e 'sub t { ($a) = @_; return $a; } $b = t(0, 1, 2); print
"$b\n"' perl -e 'sub t { @a = @_; return @a; } $b = t(0, 1, 2); print
"$b\n"'

Do I smell home work?

jue
 
A

A. Sinan Unur

Thanks!
Just needed that to clear up something...
I was somewhat uncertain about the difference between 1 and 3.

Please god forgive me for doing other people's homework!

Please Peder, do not top-post.

Sinan.
 
P

Peder Ydalus

Jürgen Exner said:
Do I smell home work?

jue

Not at all! But I have an exam tomorrow in misc scripting languages and
need to get a fair overview of perl.

As for the book question: No. That would require us to buy 5-6 books in
this single course. One for perl, one for python, one for bash, one for
tcl and so on. There is no need to be paranoid about doing someone's
homework.

- Peder -
 
U

Uri Guttman

PY> Not at all! But I have an exam tomorrow in misc scripting languages
PY> and need to get a fair overview of perl.

PY> As for the book question: No. That would require us to buy 5-6 books
PY> in this single course. One for perl, one for python, one for bash, one
PY> for tcl and so on. There is no need to be paranoid about doing
PY> someone's homework.

$DIETY help us from scripting overview courses. learn enough in 5 langs
to be dangerous. learn not enough in any to be even functional. i recall
knowing students who took a similar 5 lang in one class (way back when:
something like lisp, algol, apl, etc.) and they didn't know diddly after
the class but how to pass the exams.

when will CS profs learn that overview classes are only good for those
who can learn the langs WITHOUT the class. those who really need to be
taught will never get enough out of each lang to be useful.

now my own experience was different. in one sophomore CS class we did
projects in pdp-11 assembler, algol and lisp. never once were we taught
the languages. many of us either knew them or got the books and self
taught. the class was on programming concepts and not langs and all were
expected to be able to pick up a lang on their own. this is very
different than the overview style of class.

uri
 
A

Alan J. Flavell

Not at all! But I have an exam tomorrow in misc scripting languages and
need to get a fair overview of perl.

Yesterday I was in doubt whether to add you to my killfile.

Today, I no longer have that doubt.

Bye.
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top