Any ideas? am I calculating the substring wrong or is there a hidden character in the wordwrap string that I'm missing?#!c:/perl/bin/perl.exe use strict; use warnings; use Wx qw[:everything]; package main; unless(caller){ local *Wx::App::OnInit = sub{1}; my $app = Wx::App->new(); Wx::InitAllImageHandlers(); my $ui = Test_ui->new(); $app->SetTopWindow($ui); $ui->Show(1); $app->MainLoop(); } package Test_ui; use Wx qw[:everything :allclasses]; use Wx::Event qw(EVT_LEFT_UP); our $mainframe; our @keywords=(); use base qw(Wx::Frame); sub new { my( $self, $parent, $id, $title, $pos, $size, $style, $name ) += @_; $parent = undef unless defined $parent; $id = -1 unless defined $id; $title = "" unless defined $title; $pos = wxDefaultPosition unless defined $pos; $size = wxDefaultSize unless defined $size; $name = "" unless defined $name; $style = wxDEFAULT_FRAME_STYLE unless defined $style; $self = $self->SUPER::new( $parent, $id, $title, $pos, $size, $style, $name ); $mainframe=$self; my $main_sizer=Wx::BoxSizer->new(wxVERTICAL); $self->{keywords_text} = Wx::TextCtrl->new($self, -1, "This is a string that contains wrods and other goodie +s for my example. My problem is extracting the first word with multi +ple lines", wxDefaultPosition, wxDefaultSize, wxTE_READONLY|wxTE_MULTILINE|wxTE_WORDWRAP); $main_sizer->Add( $self->{keywords_text}, 1, wxEXPAND|wxALL, 2 +); $self->SetAutoLayout(1); $self->SetSizer($main_sizer); $self->Layout(); EVT_LEFT_UP( $self->{keywords_text}, sub { my ($self, $event) = @_; my $ip=$self->GetInsertionPoint(); my ($col,$row)=$self->PositionToXY($ip); print "row: $row\n"; print "col: $col\n"; $self->ReleaseMouse(); my $clickedline=$self->GetLineText($row); #print "clickedline : $clickedline\n"; my ($prefix) = ""; if ( $row > 0 ) { my $new_col = ($col > 0) ? ($col - $row) : $col; ($prefix) = substr($clickedline,$row,$new_col) =~ /([(\/|\ +:|\.|\n)?\w+]+)$/; } else { ($prefix) = substr($clickedline,$row,$col) =~ /([(\/|\:|\. +|\@)?\w+]+)$/; } my ($suffix)= substr($clickedline,$col,1000) =~ /^([(\/|\:|\.) +?\w+'`]+)/; my $clickedword=$prefix.$suffix; print "Prefix: $prefix\n"; print "suffix: $suffix\n"; print "clicked word: $clickedword\n"; }); return $self; } 1;
Any help would be greatly appreciated.
In reply to substring and wordwrap issue by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |