Re: how to split string(many words in one line) in a word?
by BrowserUk (Patriarch) on Oct 07, 2005 at 00:18 UTC
|
my @words = split ' ', "The quick brown (it's a slightly reddish brown
+) fox jumps over the lazy dog";
print for @words;
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.
| [reply] [d/l] |
|
|
| [reply] [d/l] [select] |
|
|
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.
| [reply] [d/l] |
|
|
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.
| [reply] [d/l] [select] |
|
|
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
| [reply] [d/l] [select] |
|
|
|
|
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;
| [reply] [d/l] |
|
|
my @words = split ' ', "The quick brown (it's a slightly reddish brown
+) fox jumps over the lazy dog";
print "$_\n" for @words;
| [reply] [d/l] |
|
|
| [reply] [d/l] |
Re: how to split string(many words in one line) in a word?
by GrandFather (Saint) on Oct 07, 2005 at 01:01 UTC
|
$_ = "The quick brown (it's a slightly reddish brown) fox jumps over t
+he lazy dog";
split;
print join "\n", @_;
Same output as BrowserUK's code purports to give.
Perl is Huffman encoded by design.
| [reply] [d/l] |
|
|
my $string = "The quick brown (it's a slightly reddish brown) fox jump
+s over the lazy dog";
my $words = join '', map { ( / / ) ? "\n" : $_ ; } split '', $string ;
print "$words" ;
| [reply] [d/l] |
|
|
gives Use of implicit split to @_ is deprecated at... under warnings;.
| [reply] [d/l] [select] |
|
|
echo "The quick brown (it's a slightly reddish brown) fox jumps over t
+he lazy dog" \
| perl -nle '$"="\n";print"@{[split]}"'
Update:
echo "The quick brown (it's a slightly reddish brown) fox jumps over t
+he lazy dog" \
| perl -ple 's/\s+/\n/g'
| [reply] [d/l] [select] |
Re: how to split string(many words in one line) in a word?
by radiantmatrix (Parson) on Oct 07, 2005 at 14:45 UTC
|
Since this appears to be your first post, you might consider reading How (Not) To Ask A Question, which should help you get better answers by asking better questions.
Also, your spelling and capitalization is atrocious. It may not matter to you, but many people will just cruise by a question with horrible spelling and grammar -- the theory being "if you don't care about your post, then you don't care about the answer". There are a number of browser plugins and the like that help with your spelling.
| [reply] |
Re: how to split string(many words in one line) in a word?
by SamCG (Hermit) on Oct 07, 2005 at 14:33 UTC
|
if i want to get a seperate word from tht how will i do that?
I couldn't even interpret what this question meant.
| [reply] |