in reply to splitting and coloring

I'd do it this way: (This requires 5.8.x)

$str = 'MKTVEQTSPTMTSEKARWIY ... ELLTDVYVSYDHEGRNG'; print join ' ', unpack '(a10)*', $_ for unpack '(a50)*', $str;; MKTVEQTSPT MTSEKARWIY QKMVEIRMFE DRVHDIFSKG EIPGFVHLYA GEEAIAVGLC AHLDHNDYIT STHRGHGHCI AKGCELDGMM AEIYGKSTGL CKGKGGSMHI ADLDRGMLGA NGIVGGGFTL AAGAALTAKF KQTGGVAVCF FGDGANNQGT FHEGINLAAI WDLPVVFVAE NNGYGEATPF HYASACEQIT DRAKGYNIPG VKVDGKDVVA VYEVAREAVE RARRGEGPTL IECITYRNYG HFEGDAQTYK TGREKEEHTE ERDAITLFEK YALSNNLLTE EAIQTVRHEV EQSVDRAVDF ANASDYPQPE ELLTDVYVSY DHEGRNG

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: spliting a lengthy text
by reasonablekeith (Deacon) on Nov 27, 2006 at 10:35 UTC
    Very nice (++) but aren't you missing the new line? ...
    print join ' ', unpack '(a10)*', "$_\n" for unpack '(a50)*', $str;
    update that newline is in the wrong place...
    print "" . join ' ', unpack '(a10)*', $_ . "\n" for unpack '(a50)*', $ +str;
    update A regex solution based on your plan of attack (if only because (un)?pack still scares me :)
    for ($str =~ /.{1,50}/g) {print join " ", /.{1,10}/g; print "\n"}
    ---
    my name's not Keith, and I'm not reasonable.

      I habitually run perl with -l enabled (see perlrun), which has the effect of setting $/ =  "\n" (and $\ = "\n"), so print adds a newline automatically. Hence the output I posted is unmodifed.

      This makes print (roughly?) equivalent to say in Perl 6.

      I also seem to recall seeing a news item that suggested that this keyword would also be available in Perl 5 as of v5.10?


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        I also seem to recall seeing a news item that suggested that this keyword would also be available in Perl 5 as of v5.10?

        Indeed it will. It is implemented as a weak keyword, thus you do have to write

        use feature 'say';

        ... to activate it. A search revealed that there were a number of modules on CPAN (predating the existence of Perl 6) that already define a routine named 'say'. Adding it as a regular keyword would have broken them, as well as unknowable amounts of code living behind firewalls that the porters could never know about.

        The Perl development team places a lot of importance in not breaking existing code (even if it means you have to resort to the above gymnastics in new code). If I remember correctly, a sitecustomize.pl program (run at the start of every incovation implicitly) will allow you to set this once and for all, for all code run on a given host.

        • another intruder with the mooring in the heart of the Perl