what would this do...

Discussion in 'Perl Misc' started by Robin, Jan 7, 2004.

  1. Robin

    Robin Guest

    @output2 = @output1[0 .. 250];

    thanks,
    -Robin
     
    Robin, Jan 7, 2004
    #1
    1. Advertisements

  2. This is an "array slice", and is shorthand for:

    @output2 = ($output1[0], $output1[1], ..., $output1[250]);

    where the "..." in the above is the missing 248 elements (2-249).

    "perldoc perldata" for gory details, search for "slice".
     
    John J. Trammell, Jan 7, 2004
    #2
    1. Advertisements


  3. Please put the subject of your article in the Subject of your article.
     
    Tad McClellan, Jan 7, 2004
    #3
  4. Robin

    Matt Garrish Guest

    Set entries 0-250 in @output2 to their equivalent values in @output1. Next
    time try running the code if you want to know what it does.

    Matt
     
    Matt Garrish, Jan 7, 2004
    #4
  5. you explanation makes it sound (at least to me) like any existing
    entries in @output2 other than 0-250 will be left alone, which they
    won't.

    @output2 will be redefined as an array with 251 entries matching those
    in locations 0-250 of @output, if any. if not, undefined.
     
    Michael Budash, Jan 7, 2004
    #5
  6. Robin

    Matt Garrish Guest

    Sorry if that's how it reads, I assumed that the OP would at least
    understand how arrays are populated in a case like this.
    Again, I would assume that the OP would understand that "equivalent" means
    that undef values remain undef, so an undef'ed array would obviously
    translate into another undefined array. If either assumption were wrong on
    my part, a quick read of the documentation and/or a little experimentation
    would have cleared up any lingering questions. This just read too much like
    a "I'm too lazy to look this up, so somebody tell me the answer" question,
    to which I abhor giving anything more than the bare minimum of information.

    Matt
     
    Matt Garrish, Jan 8, 2004
    #6
  7. No offense, but given your 'edu' address, all your questions to this group
    sound an awful lot like "Please do my homework for me". Sorry in advance
    if this isn't the case.

    Anyway, Perl has a lot of documentation. The 'perldoc' command is the way
    to get the documentation. You can also access Perl documentation at
    http://perldoc.com

    To answer your question in the shortest way possible .... take array
    elements 0 thru 250 in array @output1 and populate array @output2 with
    those elements.
    So, both @output1 and @output2 would contain the same values for elements
    0 thru 250.

    HTH

    --
    Jim

    Copyright notice: all code written by the author in this post is
    released under the GPL. http://www.gnu.org/licenses/gpl.txt
    for more information.

    a fortune quote ...
    "Don't worry about people stealing your ideas. If your ideas are
    any good, you'll have to ram them down people's throats." --
    Howard Aiken
     
    James Willmore, Jan 8, 2004
    #7
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.