what would this do...

J

John J. Trammell

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

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

Matt Garrish

Robin said:
@output2 = @output1[0 .. 250];

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
 
M

Michael Budash

Matt Garrish said:
Robin said:
@output2 = @output1[0 .. 250];

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.

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

Matt Garrish

Michael Budash said:
Matt Garrish said:
Robin said:
@output2 = @output1[0 .. 250];

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.

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.

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.
@output2 will be redefined as an array with 251 entries matching those
in locations 0-250 of @output, if any. if not, undefined.

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
 
J

James Willmore

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

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
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top