How about writing it like this ?? Assuming a) The numeric value is in 1st col and the text in 2nd col (after :) b) Wherever numeric value is not present, the text is in the first column. c) The numeric value needs to be picked up from the last successful read of the numeric value if not already defined in the input. ##########################################################################################
open(MYFILE2, " < $TMP/$D") || die "Cannot open $D: $!\n"; my @elem = (); my $storage = " "; # default value is space just in case your first record itself is not okay!! while (<MYFILE2>) { chomp; @elem = split /:/; if ($elem[1]) { push (@a1, $elem[0]); push (@a2, $elem[1]); $storage = $elem[0]; } else { push (@a1, $storage); push (@a2, $elem[0]); } } close(MYFILE2); print $_, "\n" for @a1; print $_, "\n" for @a2; __END__ ############################################################################################## it prints 13 12 12 fred nancy lional -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Monday, June 03, 2002 5:25 PM To: [EMAIL PROTECTED] Subject: manipulating arrays/scalars Hi any help appreciated... I am reading a file consisting of lines with upto 2 sets if data seperated by : ie 13:fred 12:nancy lional: each line is split into @a1 and @a2, here is my problem - if line does not have @a2 as in example line 3 above, I want it to take the value from line 2 ie - 12 here is my code that trys to do ===================================================== foreach $D (@FILES) open(MYFILE2, "$TMP/$D") || die "Cannot open $D: $!\n"; chomp (@source=<MYFILE2>); @a1=(); @a2=(); $srclen=@source; for ($a=0;$a<$srclen;$a++) ($a1[$a], $a2[$a])=split(/:/, $source[$a]); if (grep (!/^[0-9]/, $a1[$a])) #### help what needs to go here ????? ##### } } close(MYFILE2); } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]