Re: use strict; use warnings;

Discussion in 'Perl Misc' started by John Bokma, Feb 24, 2014.

  1. John Bokma

    John Bokma Guest

    Ben Morrow <> writes:

    > Perl arrays already know how long they are: you don't need to count for
    > yourself. You may not have covered this, but using an array in scalar
    > context, for example by comparing it to a number, will use the length of
    > the array. So:
    >
    > while (@hearts < 13) {
    > push @hearts, shift @startingdeck;
    > }


    or:

    @hearts = splice @startingdeck, 0, 13;

    See perldoc -f splice

    --
    John Bokma j3b

    Blog: http://johnbokma.com/ Perl Consultancy: http://castleamber.com/
    Perl for books: http://johnbokma.com/perl/help-in-exchange-for-books.html
    John Bokma, Feb 24, 2014
    #1
    1. Advertising

  2. John Bokma

    John Bokma Guest

    Marek Novotny <> writes:

    > On Mon, 24 Feb 2014 11:52:38 -0600, John Bokma wrote:
    >
    >> Ben Morrow <> writes:
    >>
    >>> Perl arrays already know how long they are: you don't need to count for
    >>> yourself. You may not have covered this, but using an array in scalar
    >>> context, for example by comparing it to a number, will use the length
    >>> of the array. So:
    >>>
    >>> while (@hearts < 13) {
    >>> push @hearts, shift @startingdeck;
    >>> }

    >>
    >> or:
    >>
    >> @hearts = splice @startingdeck, 0, 13;
    >>
    >> See perldoc -f splice

    >
    > Hi John,
    >
    > The objective asked me to use pop, push and shift. No splice. He who
    > controls the splice, controls the universe! HA... Oh wait... ;-)


    Clear. pop, push, and shift (and unshift) are all sugared versions of
    splice, which is good to know anyway, IMO

    I wouldn't see the use of splice as a violation of the requirements, but
    I am not your teacher ;-)

    --
    John Bokma j3b

    Blog: http://johnbokma.com/ Perl Consultancy: http://castleamber.com/
    Perl for books: http://johnbokma.com/perl/help-in-exchange-for-books.html
    John Bokma, Feb 24, 2014
    #2
    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. Marius Gavrilescu

    Re: use strict; use warnings;

    Marius Gavrilescu, Feb 24, 2014, in forum: Perl Misc
    Replies:
    152
    Views:
    506
    $Bill
    Mar 11, 2014
  2. Kaz Kylheku

    Re: use strict; use warnings;

    Kaz Kylheku, Feb 24, 2014, in forum: Perl Misc
    Replies:
    0
    Views:
    67
    Kaz Kylheku
    Feb 24, 2014
  3. George Mpouras

    Re: use strict; use warnings;

    George Mpouras, Feb 24, 2014, in forum: Perl Misc
    Replies:
    0
    Views:
    57
    George Mpouras
    Feb 24, 2014
  4. Mart van de Wege

    Re: use strict; use warnings;

    Mart van de Wege, Feb 24, 2014, in forum: Perl Misc
    Replies:
    1
    Views:
    54
    Mart van de Wege
    Feb 25, 2014
  5. Justin C

    Re: use strict; use warnings;

    Justin C, Feb 24, 2014, in forum: Perl Misc
    Replies:
    2
    Views:
    78
    Justin C
    Feb 25, 2014
Loading...

Share This Page