in reply to Re: how to split string(many words in one line) in a word?
in thread how to split string(many words in one line) in a word?

Except that the output generated is:

Thequickbrown(it'saslightlyreddishbrown)foxjumpsoverthelazydog

However this:

print join "\n", split ' ', "The quick brown (it's a slightly reddish brown) fox jumps over the lazy dog";

does the trick


Perl is Huffman encoded by design.

Replies are listed 'Best First'.
Re^3: how to split string(many words in one line) in a word?
by BrowserUk (Patriarch) on Oct 07, 2005 at 02:49 UTC

    That is real output as generated from my "perl shell"--which has -l in force.

    The same effect can be seen by:

    P:\test>perl -wle"print for split ' ', shift" "The quick brown (it's a + slightly reddish brown) fox jumps over the lazy dog The quick brown (it's a slightly reddish brown) fox jumps over the lazy dog

    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".
    The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.
Re^3: how to split string(many words in one line) in a word?
by tinita (Parson) on Oct 07, 2005 at 08:08 UTC
    i always start perl on the commandline with -wle. i would do that even while sleeping.
    that saves me from doing "...\n" instead of ... and -w saves me from bugs.
    i don't have an alias for that, but i'm typing it automatically. perl -e'' looks very odd to me.
Re^3: how to split string(many words in one line) in a word?
by Skeeve (Parson) on Oct 07, 2005 at 05:53 UTC
    Sorry, but why split if you don't store it and join it directly? I know, it's the homework answer to split, but your's will be more efficient, I guess this way:
    s/\s+/\n/;print;

    $\=~s;s*.*;q^|D9JYJ^^qq^\//\\\///^;ex;print

      Actually I don't think the homework required a split answer. But there is a tradition of providing a somewhat obscure answer to questions that look like homework. If OP asks questions, well and good. If not then they probably can't simply regurgitate the "answers" they have been given and expect to get good marks for it.


      Perl is Huffman encoded by design.
Re^3: how to split string(many words in one line) in a word?
by g0n (Priest) on Oct 07, 2005 at 08:45 UTC
    The OP asked: "if i want to get a seperate word from tht how will i do that? ". BrowserUKs answer does what he/she asked for. The concatenation of the words is an artefact of the print output used to demonstrate that it works, rather than the operation the OP was asking about.

    --------------------------------------------------------------

    $perlquestion=~s/Can I/How do I/g;