Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Ter::ANSIColor is awesome, but.. (need help)

by Corion (Pope)
on Mar 30, 2014 at 13:32 UTC ( #1080288=note: print w/replies, xml ) Need Help??

in reply to Term::ANSIColor is awesome, but.. (need help)

Separate the program logic and the output.

Within your program, always keep $name eq 'Jon', and have a routine, output_name(), which does

print colored($name,'red');

or a function visual_name, which returns the value, ready for printing as name:

sub visual_name { my( $name )= @_; colored( $name, 'red' ); };

Replies are listed 'Best First'.
Re^2: Ter::ANSIColor is awesome, but.. (need help)
by mascip (Pilgrim) on Mar 30, 2014 at 13:49 UTC

    Thank you Corion.
    That makes sense, but it doesn't exactly solve my problem. I don't want to make this change in every part of the code where I'm displaying something.

    I guess, most of my print statements are in the same file in fact, apart from exceptions. (Edit: In fact I just realized that I would really like these exceptions to be colourized...)

    I'll try this tomorrow. But I'm still wondering if there is a better way...

      The starting point of my reasoning is:

      There is only one place where I declare the variables that I want to colorize. If I could colorize them then and nowhere else, that would be much simpler.

        You will need to split up the two uses of $name, for internal program logic and for display.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1080288]
[talexb]: Does the mis-spelled title "SSL Apgrade failed" bug anyone else? Wish the authour would fix it. This is the node I'm talking about.

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (10)
As of 2017-07-25 17:35 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (376 votes). Check out past polls.