in reply to Add hyperlink to paticular lines of MS doc
G'day Akku,
I'm not in a position to test this: no Perl on MSWin; no MS Word; no Win32::OLE. However, I see some anomalies in your code which might be the cause of the problem.
Without changing any other parts of your code, would your for loop code be better as something closer to this:
my ($c, $start, $end) = (2, 0, 0); foreach $elemetns(keys %hash) { $start = $end; $end += length $elemetns; ... my $r = $document->Range($start, $end); ... }
[Note: The += is a guess; it depends on how Range() works; just = might be correct.]
Unrelated to your current issue but possibly a source of confusion or errors later on:
So, I'd suggest these changes:
... my @elements = ( 'This is a test line', 'This is second test Line', 'This is the third line', ); ... my ($c, $start, $end) = (2, 0, 0); for my $element (@elements) { $start = $end; $end += length $element; ... my $r = $document->Range($start, $end); ... }
$c and $r are also problematical. They're basically meaningless names which conveyed nothing when I first encountered them. Perhaps $colour_index and $range would be better names.
Also, you assign $c = 2. What does '2' mean? While you may know today, will you when you revisit this code at some later time. Will the next maintainer know? Either use a meaningfully named constant or add a comment explaining what '2' refers to. As a general rule, arbitrary constant numbers popping in pieces of code are difficult to understand (without doing extra research which shouldn't be necessary) and are error-prone.
-- Ken
|
|---|