Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting Array Values

Status
Not open for further replies.

damarious

Programmer
Oct 31, 2000
4
US
I read a file into an array like this:
open(HANDLE.&quot;<$filenamevar&quot;);
@arrayname = <HANDLE>;
close(HANDLE);

I need to search through the array for a certain string... I can do that no problem.

Then I need to insert new data after that without overwriting...

EXAMPLE:
an array with the following values

1
2
3
4
5
6

would become:

1
2
a
b
c
d
3
4
5
6

What would be my best approach?
 
Code:
#!/usr/local/bin/perl
@vals = ('1','2','3','4','5','6');
@alpha = ('a','b','c');

splice @vals,2,0,@alpha;

print &quot;@vals\n&quot;;
'hope this helps...




keep the rudder amid ship and beware the odd typo
 
BINGO! I ~knew~ splice was it, I just didn't grasp the example in my book... THANKS!
 
Hi

What do I do if I need to append 'a b c' to a array value in $val[1]

To obtain like this 1, 2abc, 3, 4, ..

Preethi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top