Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

In a program I'm reading data from a file and then - since Tk GUI data fields are too narrow - I'm adding missing data as balloons.

This is a modul where I push a "\n" behind periods and commas in order to make balloons less wide.

$requirement=~s/. /.\\n/g; $requirement=~s/, /,\\n/g; push(@CHECKLIST,{ ... _4_requirement=>$requirement });

This is a part where I define Tk frames, an entry and a balloon:

my $article00_Tk=$L00_Tk->Frame()->pack(-side=>'left',-padx=>1,-pady=> +0); my $article00_L=$article00_Tk->Entry(-relief=>'ridge',-borderwidth=>2, +-text=>$CHECKLIST[0]->{_1_article},-font=>'Arial 8',-width=>15,-state +=>'disabled')->pack(); my $article00_L_Balloon=$article00_L->Balloon(); $article00_L_Balloon->attach($article00_L,-balloonposition=>'widget',- +msg=>$CHECKLIST[0]->{_4_requirement}); my $article00_Tk=$L00_Tk->Frame()->pack(-side=>'left',-padx=>1,-pady=> +0); my $article00_L=$article00_Tk->Entry(-relief=>'ridge',-borderwidth=>2, +-text=>$CHECKLIST[0]->{_1_article},-font=>'Arial 8',-width=>15,-state +=>'disabled')->pack(); my $article00_L_Balloon=$article00_L->Balloon();

If the same text is inserted manually (copy / paste) the inserted \n causes line break correctly, but if it's taken from an array the balloon is shown as a single line where \n is shown as a part of string.

a) $article00_L_Balloon->attach($article00_L,-balloonposition=>'wid +get',-msg=>" text ...."); b) $article00_L_Balloon->attach($article00_L,-balloonposition=>'wid +get',-msg=>$CHECKLIST[0]->{_4_requirement});

Do you have any idea what am I missing?

Thanks for help.

M

Replies are listed 'Best First'.
Re: Balloons msg
by AnomalousMonk (Archbishop) on May 21, 2020 at 18:17 UTC
    $requirement=~s/. /.\\n/g; $requirement=~s/, /,\\n/g;
    ...
    ... if it's taken from an array the balloon is shown as a single line where \n is shown as a part of string.

    Something like  $requirement=~s/. /.\\n/g substitutes a literal  '\n' (backslash character '\' followed by an 'n' character) into the  $requirement string. You want  \n instead:
        $requirement=~s/. /.\n/g;
    (Update: Remember that the replacement field of the  s/// operator follows double-quote string interpolation rules unless  '...' (single-quote) delimiters are used.)

    Update: A more concise and general substitution would be
        $requirement =~ s{ (?<= [,.]) [ \t] }{\n}xmsg;
    to cover both cases in one swell foop.


    Give a man a fish:  <%-{-{-{-<