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

This node falls below the community's minimum standard of quality and will not be displayed.

Replies are listed 'Best First'.
Re: color a letter in an array
by davorg (Chancellor) on Nov 23, 2006 at 14:06 UTC

    The method that you would use to output text in colour is completely dependent on how you are displaying your output. For a web page you might use CSS. For a console you might use Curses or ANSI escape codes. Without knowing how you are displaying your output, it's impossible to tell you how to do this.

    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

Re: color a letter in an array
by johngg (Canon) on Nov 23, 2006 at 14:24 UTC
    As well as not telling us how you hope to display your results, as pointed out by davorg, you have not told us how you get 'ANBCDFSEKAR' from your data. The letters 'S', 'E', 'K', 'A' and 'R' occur next to each other three times in your data, but nowhere in association with 'ANBCDF'. Perhaps you could explain further so that we can try to help you.

    Cheers,

    JohnGG

Re: color a letter in an array
by roboticus (Chancellor) on Nov 23, 2006 at 14:52 UTC
Re: color a letter in an array
by johngg (Canon) on Nov 23, 2006 at 23:14 UTC
    There is still a little confusion about what you mean and I think you are getting some terms mixed up. It is not clear from your post that the "original array" is indeed an array. It could be if declared like

    my @originalArray = qw{D F Y I N G W};

    or it could be a space separated string like

    my $originalString = q{D F Y I N G W};

    Your "output array" is not an array, it is a scalar containing a string. If your original array is an array you need to turn it into a string so you can search it. Do something like

    my $stringToSearch = join q{}, @originalArray;

    However, if it already was a string with spaces in it, you need to remove those with a global replace

    (my $stringToSearch = $originalString) =~ s{\s+}{}g;

    Once you have a contiguous string of letters you can do another global replace looking for "SEKAR" and using parentheses () which are regular expression memory. For example, if you do $string =~ m{(SEKAR)}; then if the match succeeds the string "SEKAR" will be placed in the special read-only variable $1 for later use. So you could now do

    $stringToSearch =~ s{(SEKAR)}{<sometag>$1</sometag>}g;

    That will replace every occurrence of SEKAR in the string with <sometag>SEKAR</sometag>.

    I hope this will give you enough pointers to get started.

    Cheers,

    JohnGG

Re: color a letter in an array
by Joost (Canon) on Nov 23, 2006 at 14:58 UTC
Re: color a letter in an array
by zentara (Cardinal) on Nov 23, 2006 at 17:13 UTC
Re: color a letter in an array
by Jenda (Abbot) on Nov 24, 2006 at 01:51 UTC

    If this is not homework then I don't know what would be. Why do these people think their teacher doesn't read PerlMonks? If I were the teacher then dear Tony would be sure to receive a solution tainted so that I can get to know who he is when he finaly submits the homework. And he would not like the outcome.

Re: color a letter in an array
by l.frankline (Hermit) on Nov 24, 2006 at 08:46 UTC

    hi,

    the below code will certainly help you.

    @arr = (A..H,S,E,K,A,R,J..T,S,E,K,A,R,A..Z);
    $text =  join "",@arr;
    $text =~s#SEKAR#<font>$&</font>#g;
    print $text;

    Result:

    ABCDEFGH<font>SEKAR</font>JKLMNOPQRST<font>SEKAR</font>ABCDEFGHIJKLMNOPQRSTUVWXYZ

    bye

    Don't put off till tomorrow, what you can do today.