Re: How to split a string read from the file?
- From: usenet@xxxxxxxxxxxxxxx
- Date: 29 Mar 2006 11:42:10 -0800
pangzhy@xxxxxxxxx wrote:
I want to clear the number and colon at the beginning of each line
Why are you slurping the file into an array (instead of just iterating
over the source file)? Why are you using split instead of a regular
expression? Why are you using all those intermediate variables? Your
task can be made much easier:
#!/usr/bin/perl
use warnings; use strict;
while (<DATA>) { #you would use a handle to your file here
s/^\d+\s*: ?// && print;
}
__DATA__
1 : #!/usr/local/bin/perl
2 :
3 : while ($inputline = <STDIN>) {
4 : while ($inputline =~ /\b[A-Z]\S+/g) {
5 : $word = $&;
6 : $word =~ s/[;.,:-]$//; # remove punctuation
7 : for ($count = 1; $count <= @wordlist;
8 : $count++) {
9 : $found = 0;
10: if ($wordlist[$count-1] eq $word) {
11: $found = 1;
12: $wordcount[$count-1] += 1;
13: last;
--
http://DavidFilmer.com
.
- References:
- How to split a string read from the file?
- From: pangzhy
- How to split a string read from the file?
- Prev by Date: Re: Whimsical Question
- Next by Date: Re: Whimsical Question
- Previous by thread: Re: How to split a string read from the file?
- Next by thread: Re: How to split a string read from the file?
- Index(es):
Relevant Pages
|