How to split a string read from the file?
- From: pangzhy@xxxxxxxxx
- Date: Wed, 29 Mar 2006 20:44:45 +0800
dear all , I'am trying to write a script to neaten files as follows:
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;
I want to clear the number and colon at the beginning of each line and wirte
a perl script
#/usr/bin/perl -w
use strict ;
open MYFILE , "my.txt" ;
my @array=<MYFILE>;
my $count=0;
my @temp;
my $sum=0;
for($count=0;$count lt @array ; $count++){
(my $number,$temp[$sum])=split (/:/,$array[$count]);
print $number,"\n";
$sum++;
}
print @temp;
but the output just three lines instead of 17
--
Terry Pang
- Follow-Ups:
- Re: How to split a string read from the file?
- From: Gerard Robin
- Re: How to split a string read from the file?
- From: John W. Krahn
- Re: How to split a string read from the file?
- From: usenet
- Re: How to split a string read from the file?
- From: Jay Savage
- Re: How to split a string read from the file?
- From: Mr. Shawn H. Corey
- Re: How to split a string read from the file?
- Prev by Date: can not filter out commentary lines with reg-exps
- Next by Date: Re: can not filter out commentary lines with reg-exps
- Previous by thread: can not filter out commentary lines with reg-exps
- Next by thread: Re: How to split a string read from the file?
- Index(es):
Relevant Pages
|