Your question is still not completely clear to me. A good tool for this job is "regular expressions" or regex for short. If the regex succeeds, the left hand side assignment is defined otherwise it is not.
As an update note: If for some reason this doesn't do exactly what you want, I expect you to spend some time studying the code and for you to make a serious attempt at modifications. I think you are doomed if you just copy code without understanding how it works.
#!/usr/bin/perl
use strict;
use warnings;
use List::Util qw(sum);
while (<DATA>)
{
my ($var) = /:\>\>(\w+)/; # could have been done
my (@nums) = /,\s*(\d+)/g; # on one line...
next unless $var; # skips bogus lines
print "$var,",sum(@nums),"\n";
}
#prints:
#test,10
#test1,26
__DATA__
<"Session Date:Mar 13/2017
":>>test", 1,2,3,4
":>>test1", 5,6,7,8
end>
|