in reply to Re: Re: Re: I'm so confused
in thread I'm so confused
But if you had stored the newlines in the array, the last ' in each line would've been pushed to the next line by the newline character stored in the array:my @out = qw(one two three four five six seven eight nine); my $i = 0; foreach (@out) { print "\$out[",$i++,"] = '$_'\n"; } =output= $out[0] = 'one' $out[1] = 'two' $out[2] = 'three' $out[3] = 'four' $out[4] = 'five' $out[5] = 'six' $out[6] = 'seven' $out[7] = 'eight' $out[8] = 'nine'
You have more flexibility if you store only the data.=output= $out[0] = 'one ' $out[1] = 'two ' $out[2] = 'three ' $out[3] = 'four ' $out[4] = 'five ' $out[5] = 'six ' $out[6] = 'seven ' $out[7] = 'eight ' $out[8] = 'nine '
In your example @out = join "\n", @out; you are destroying your array. Instead of the output above you would get the following output using the same print loop:
Instead of having 9 rows you now have only one row made up of a string with interspersed newlines. As a rule, most people don't print an array using print @array; except when debugging.my @out = qw(one two three four five six seven eight nine); @out = join "\n", @out; my $i = 0; foreach (@out) { print "\$out[",$i++,"] = '$_'\n"; } =output= $out[0] = 'one two three four five six seven eight nine'
Try playing around with the print loop above to test other types of array manipulation. It will give you a better idea of how your data is stored in the array structure.
--Jim
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: Re: I'm so confused
by dragonchild (Archbishop) on Nov 26, 2001 at 20:47 UTC |