Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > short script differences

Reply
Thread Tools

short script differences

 
 
Peder Ydalus
Guest
Posts: n/a
 
      01-14-2004
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"'

 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      01-14-2004
Peder Ydalus <(E-Mail Removed)> wrote in news:bu22ej$arb$1
@maud.ifi.uio.no:

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

--
A. Sinan Unur
http://www.velocityreviews.com/forums/(E-Mail Removed) (reverse each component for email address)
 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      01-14-2004
Peder Ydalus wrote:
> Just needed that to clear up something...


It's called home work. Don't you use books in school nowadays?

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

 
Reply With Quote
 
Peder Ydalus
Guest
Posts: n/a
 
      01-14-2004
Thanks!
Just needed that to clear up something...

- P -


A. Sinan Unur wrote:
> Peder Ydalus <(E-Mail Removed)> wrote in news:bu22ej$arb$1
> @maud.ifi.uio.no:
>
>
>>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.
>



--
Det er bedre å putte nesen sin i andres ting
enn å putte andres ting i nesen

http://www.stud.ifi.uio.no/~pedery

 
Reply With Quote
 
Peder Ydalus
Guest
Posts: n/a
 
      01-14-2004
Thanks!
Just needed that to clear up something...
I was somewhat uncertain about the difference between 1 and 3.

- P -


A. Sinan Unur wrote:
> Peder Ydalus <(E-Mail Removed)> wrote in news:bu22ej$arb$1
> @maud.ifi.uio.no:
>
>
>>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.
>



--
Det er bedre å putte nesen sin i andres ting
enn å putte andres ting i nesen

http://www.stud.ifi.uio.no/~pedery

 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      01-14-2004
Peder Ydalus wrote:
> 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


 
Reply With Quote
 
Robin
Guest
Posts: n/a
 
      01-14-2004
the third one is an array that @_ equals and that's different than a
scalar..

--
Regards,
Robin
--
(E-Mail Removed)
--


 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      01-14-2004
Peder Ydalus <(E-Mail Removed)> wrote in
news:bu2443$at9$(E-Mail Removed):

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

--
A. Sinan Unur
(E-Mail Removed) (reverse each component for email address)
 
Reply With Quote
 
Peder Ydalus
Guest
Posts: n/a
 
      01-14-2004
Jürgen Exner wrote:
>
> 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 -

 
Reply With Quote
 
Uri Guttman
Guest
Posts: n/a
 
      01-14-2004
>>>>> "PY" == Peder Ydalus <(E-Mail Removed)> writes:

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

--
Uri Guttman ------ (E-Mail Removed) -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DEVELOP THE WINNING EDGE, SMALL DIFFERENCES IN YOUR PERFORMANCE CANLEAD TO LARGE DIFFERENCES IN YOUR RESULTS Home_Job_opportunity C Programming 0 01-14-2009 03:51 PM
DEVELOP THE WINNING EDGE, SMALL DIFFERENCES IN YOUR PERFORMANCE CANLEAD TO LARGE DIFFERENCES IN YOUR RESULTS Home_Job_opportunity C Programming 0 01-08-2009 04:31 PM
unsigned short, short literals Ioannis Vranos C Programming 5 03-05-2008 01:25 AM
longs, long longs, short short long ints . . . huh?! David Geering C Programming 15 01-11-2007 09:39 PM
unsigned short short? slougheed@gmail.com C++ 4 10-16-2006 11:25 PM



Advertisments