Cody Fendant has asked for the wisdom of the Perl Monks concerning the following question:
I have a situation where I'm reading from an unreliable source of data.
Essentially, if I split a line and there are only 6 elements, I've got a problem, because there should be 7. The extra one should be at index 1.
['foo' , 'bar', 'baz', 'etc', 'etc', 'etc'] ##problem line ['foo' , '', 'bar', baz', 'etc', 'etc', 'etc'] ## problem now fixe +d.
What's the elegant or Perlish way to do this? Doing it this way:
@newline = ($line[0], '',@line[ 1, 2, 3, 4, 5 ]);Doesn't seem so great.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Ways to add an item into the middle of an array?
by choroba (Cardinal) on Nov 20, 2015 at 00:49 UTC | |
by Cody Fendant (Hermit) on Nov 20, 2015 at 04:02 UTC | |
|
Re: Ways to add an item into the middle of an array?
by vinoth.ree (Monsignor) on Nov 20, 2015 at 04:01 UTC |