I understand the general aim of the following piece of code (i.e. sum up the numeric part of the string, e.g. for currstr="3S47M" then seqlength=50).
But could someone explain me what is happening line by line ?
In particular, I have issue to understand what value where
is holding at each turn. More precisely, I don't understand the part with the scalar
function ("scalar($RLENGTH = length($&), $RSTART = length($`)+1)") ?
Is it correct that the assignment of RLENGTH
and RSTART
take place inside scalar
?
Why using comma-separated assignment within scalar
? What does it mean ? And what is then the result of its evaluation ?
If anybody could help, I will be very very grateful !
Thanks
Erica
my $seqlength=0;
my $currstr="3S47M";
my $where = $currstr =~ /[0-9]+[M|D|N|X|=|S|H|N]/
? scalar($RLENGTH = length($&), $RSTART = length($`)+1) : 0;
while ($where > 0) {
$seqlength += substr($currstr, ($where)-1, $RLENGTH - 1) + 0;
$currstr = substr($currstr, ($where + $RLENGTH)-1);
$where = $currstr =~ /[0-9]+[M|D|N|X|=|S|H|N]/
? scalar($RLENGTH = length($&), $RSTART = length($`)+1) : 0;
}
edit: what is the purpose of RSTART
? why writing scalar($RLENGTH = length($&)
will not work ?