in reply to foreach increment problem?
Is this a Tk::Text widget? 'cause the docs say:
$text->get(index1, ?index2?)
Return a range of characters from the text. The return value will be all the characters in the text starting with the one whose index is index1 and ending just before the one whose index is index2 (the character at index2 will not be returned). If index2 is omitted then the single character at index1 is returned. If there are no characters in the specified range (e.g. index1 is past the end of the file or index2 is less than or equal to index1) then an empty string is returned. If the specified range contains embedded windows, no information about them is included in the returned string.
It doesn't say anything about returning an array, so I gotta tell you, no you don't have a "find" function that loads the entire contents of "$t" into an array. You have a "find" function that assigns a scalar to an array such that it becomes the array's first element. You want it broken by lines, you'll have to do it yourself.
my $text = $t->get("1.0", "end"); foreach my $line (split /\n/, $text) {
Unrelated error: your regexp needs /'s instead of double-quotes, or an 'm' in front of the opening double-quote (or 'm' in front of numerous other possible delimiters.)
Unrelated style note: for loops assign to $_ by default if nothing else is specified. People don't usually assign to $_ by hand. And regexps are against $_ by default. So you could use your own named variable as I do above, or you could just:
for (split /\n/, $text) { if (/\b$string\b/) {
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: foreach increment problem?
by Grygonos (Chaplain) on Dec 05, 2003 at 19:41 UTC | |
|
Re: Re: foreach increment problem?
by Elijah (Hermit) on Dec 05, 2003 at 19:44 UTC |