Steven Massey wrote:
>
> Hi any help appreciated...
Hello,
> 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);
> }
Here is one way to do it:
local @ARGV = map "$TMP/$_", @FILES;
my $number;
while ( <> ) {
chomp;
if ( /^(\d+):(.+)$/ ) {
print "Name: $2\nNumber: $1\n";
$number = $1;
}
elsif ( /([^:]+)/ and defined $number ) {
print "Name: $1\nNumber: $number\n";
}
elsif ( eof ) {
$number = undef;
}
else {
print "Error: no data found!\n";
}
}
__END__
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]