short script differences

Discussion in 'Perl Misc' started by Peder Ydalus, Jan 14, 2004.

  1. Peder Ydalus

    Peder Ydalus Guest

    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"'
    Peder Ydalus, Jan 14, 2004
    #1
    1. Advertising

  2. Peder Ydalus <> 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
    (reverse each component for email address)
    A. Sinan Unur, Jan 14, 2004
    #2
    1. Advertising

  3. 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
    Gunnar Hjalmarsson, Jan 14, 2004
    #3
  4. Peder Ydalus

    Peder Ydalus Guest

    Thanks!
    Just needed that to clear up something...

    - P -


    A. Sinan Unur wrote:
    > Peder Ydalus <> 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
    Peder Ydalus, Jan 14, 2004
    #4
  5. Peder Ydalus

    Peder Ydalus Guest

    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 <> 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
    Peder Ydalus, Jan 14, 2004
    #5
  6. 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
    Jürgen Exner, Jan 14, 2004
    #6
  7. Peder Ydalus

    Robin Guest

    the third one is an array that @_ equals and that's different than a
    scalar..

    --
    Regards,
    Robin
    --

    --
    Robin, Jan 14, 2004
    #7
  8. Peder Ydalus <> wrote in
    news:bu2443$at9$:

    > 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
    (reverse each component for email address)
    A. Sinan Unur, Jan 14, 2004
    #8
  9. Peder Ydalus

    Peder Ydalus Guest

    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 -
    Peder Ydalus, Jan 14, 2004
    #9
  10. Peder Ydalus

    Uri Guttman Guest

    >>>>> "PY" == Peder Ydalus <> 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 ------ -------- http://www.stemsystems.com
    --Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
    Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
    Uri Guttman, Jan 14, 2004
    #10
  11. On Wed, 14 Jan 2004, Peder Ydalus wrote:

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


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

    Today, I no longer have that doubt.

    Bye.
    Alan J. Flavell, Jan 14, 2004
    #11
    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. David Geering

    longs, long longs, short short long ints . . . huh?!

    David Geering, Jan 8, 2007, in forum: C Programming
    Replies:
    15
    Views:
    558
    Keith Thompson
    Jan 11, 2007
  2. Replies:
    4
    Views:
    819
    Kaz Kylheku
    Oct 17, 2006
  3. Ioannis Vranos

    unsigned short, short literals

    Ioannis Vranos, Mar 4, 2008, in forum: C Programming
    Replies:
    5
    Views:
    674
    Eric Sosman
    Mar 5, 2008
  4. Home_Job_opportunity
    Replies:
    0
    Views:
    497
    Home_Job_opportunity
    Jan 8, 2009
  5. Home_Job_opportunity
    Replies:
    0
    Views:
    584
    Home_Job_opportunity
    Jan 14, 2009
Loading...

Share This Page