milma has asked for the wisdom of the Perl Monks concerning the following question:
Could somebody please explain why the expected message is not printed from the code below. I assumed that the regex will return true when a replacement is done, but it makes the replacement and returns false
use strict; use warnings; use Tk; use Tk::BrowseEntry; my %CFG = ( 'target' => 'foobar' ); my $main = MainWindow->new(); my $entry = $main->BrowseEntry( -variable=>\$CFG{target}, ); $entry->grid( -row=>1, -column=>1, ); my $continue = $main->Button( -command=>\&continue, -text=>'run', ); $continue->grid( -row=>2, -column=>1, ); sub continue { warn "$CFG{target}\n"; if ( $CFG{target} =~ s/bar//xms ) { warn "expecting this message\n"; } warn "$CFG{target}\n"; } MainLoop();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: search and replace regex return value
by shmem (Chancellor) on May 07, 2017 at 10:05 UTC | |
by haukex (Archbishop) on May 07, 2017 at 15:53 UTC | |
|
Re: Tk textvariable search and replace regex return value
by Anonymous Monk on May 07, 2017 at 10:15 UTC | |
|
Re: search and replace regex return value
by milma (Initiate) on May 07, 2017 at 14:02 UTC | |
by LanX (Saint) on May 07, 2017 at 14:15 UTC | |
by haukex (Archbishop) on May 07, 2017 at 14:47 UTC | |
by LanX (Saint) on May 07, 2017 at 16:23 UTC | |
by haukex (Archbishop) on May 07, 2017 at 17:00 UTC | |
by milma (Initiate) on May 07, 2017 at 20:36 UTC |