> Sudhindra K S wrote: > > I have a file with lines as shown below > > //abc/... - //xyz/... > //abc1/... - //xyz1/... > > Now i want to split the lines at "-" and get the string on the left in one > array and the string on the right in another array. > > ie: array1 = (//abc, //abc1) and array2 = (//xyz, //xyz1). > > How do i do this?
Names are useful handles to think about things with. By abstracting as far as you have, with abc, xyz, @array1, @array2 and so on, you've thrown away the clues that would help us to help you. Intriguingly you've left in the double and single slashes that make this look like you could be dealing with URLs? Anyway, your data looks like <label> - <information> without knowing more, and assuming that neither the <label> nor the <information> contains whitespace, I'd write: use strict; use warnings; open FILE, 'file.txt' or die $!; my @array1; my @array2; while (<FILE>) { my ($label, $hyphen, $info) = split; die unless $hyphen eq '-'; push @array1, $label; push @array2, $info; } HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>