Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

coloring patterns of an array

by Tony1 (Novice)
on Feb 05, 2007 at 05:33 UTC ( [id://598254]=perlquestion: print w/replies, xml ) Need Help??

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

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: coloring patterns of an array
by chargrill (Parson) on Feb 05, 2007 at 05:43 UTC

    First, that looks like a scalar to me, not an array. An array looks like this in perl:

    @array = ( 'M', 'A', 'S', 'K', ...);

    Second, what have you tried?

    I immediately think to use a regular expression, wherein I would match 3 or more repeating 'S' characters, capture that match, and surround the match by your font tags in the right hand side of said regular expression.

    Look into s/// in "Regexp quote-like operators" at perlop. In particular, pay attention to the use of capturing parenthesis (), the special $1 backreference variable, the {} quantifiers (specifically look for "Match at least n times"), and the /g global modifier.

    After you've given it an effort, and if you're still having trouble, let us know - we'll be happy to help.

    Update: Taking a second look, you'll also need to decide if you want to add spaces, as you have in your example, or whether that was a typo.



    --chargrill
    s**lil*; $*=join'',sort split q**; s;.*;grr; &&s+(.(.)).+$2$1+; $; = qq-$_-;s,.*,ahc,;$,.=chop for split q,,,reverse;print for($,,$;,$*,$/)
Re: coloring patterns of an array
by Samy_rio (Vicar) on Feb 05, 2007 at 05:51 UTC

    Hi Tony1, try like this

    use strict; use warnings; my $str = 'mASVKSSSSSSSSSFISLLLLILLVIVLQSQVIECQPQQSCTASLTGLNVCAPFLVPGS +PTASTECCNAVQSINHDCMCNTMRIAAQIPAQCNLPPLSCSANSSS'; $str =~ s/(.{10})/$1 /g; $str =~ s/(S{3,})/<font color=red>$1<\/font>/g; $str =~ s/<\/font> <font color=red>/ /g; print $str; __END__ Output is: ---------- mASVK<font color=red>SSSSS SSSS</font>FISLLL LILLVIVLQS QVIECQPQQS CTA +SLTGLNV CAPFLVPGSP TASTECCNAV QSINHDCMCN TMRIAAQIPA QCNLPPLSCS AN<fon +t color=red>SSS</font>

    Look into this How (Not) To Ask A Question

    chargrill++

    Regards,
    Velusamy R.


    eval"print uc\"\\c$_\""for split'','j)@,/6%@0%2,`e@3!-9v2)/@|6%,53!-9@2~j';

Re: coloring patterns of an array
by marto (Cardinal) on Feb 05, 2007 at 09:58 UTC
    Tony1,

    This looks very similar to your previous post color a letter in an array. Was there anything covered in the replies to your previous question that you did not understand?

    Martin
Re: coloring patterns of an array
by johngg (Canon) on Feb 05, 2007 at 10:04 UTC
    Hi Tony1,

    You've asked a very similar question here before. What didn't you understand about the advice you were given before when looking at this new problem? You still seem to be confusing strings and arrays. Perhaps you should take a little time to read perldata which will explain Perl's different data types.

    Cheers,

    JohnGG

    A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://598254]
Approved by chargrill
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-04-24 21:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found