Re: How to split a string read from the file?



On Wed, 2006-29-03 at 20:44 +0800, 庞 wrote:
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++){

for( $count = 0; $count < @array; $count ++ ){
# 'lt' is for strings, '<' is for numbers

(my $number,$temp[$sum])=split (/:/,$array[$count]);
print $number,"\n";
$sum++;
}


print @temp;


but the output just three lines instead of 17


--
Terry Pang
--
__END__

Just my 0.00000002 million dollars worth,
--- Shawn

"For the things we have to learn before we can do them,
we learn by doing them."
Aristotle

* Perl tutorials at http://perlmonks.org/?node=Tutorials
* A searchable perldoc is at http://perldoc.perl.org/



.



Relevant Pages

  • Re: How to split a string read from the file?
    ... use strict; ... open MYFILE, "my.txt"; ... print @temp; ...
    (perl.beginners)
  • Re: Pass a value to Perl script
    ... > I have this perl script which is taking value from an external ... > the variable my $path (which is taking value from external app). ... > use strict; ... > print STDOUT $base; ...
    (perl.beginners)
  • Re: matching pattern & printing
    ... > In the following perl script, I would like to print all the lines in a ... > use strict; ... > use warnings; ... metachar in your regex ...
    (perl.beginners)
  • Re: evaluate sine series.
    ... use warnings; ... use strict; ... Write a perl script to check whether a given file format ... Write a perl script to download a protein sequence from ...
    (comp.lang.perl.misc)
  • Re: side by side concatenation
    ... > I am trying to write a perl script to make it.. ... > any advice??? ... use warnings; ... use strict; ...
    (comp.lang.perl.misc)