dear  Shawn & Jay
problem solved by using '<' instead of 'lt'
but the $temp[2] is undefined
which means the pattern is not appropriate



在06-3-29,Jay Savage <[EMAIL PROTECTED]> 写道:
>
> On 3/29/06, 庞 <[EMAIL PROTECTED]> wrote:
> > dear all , I'am trying to write a script to neaten files as follows:
> >
>
> > 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
> >
> >
>
> Which output is 3 lines? 'print @temp?' or does $sum == 3?. There are
> a number of things that could be happening here. First, print uses a
> space, not a newline, to separate the elements of @temp when they're
> printed to screen. You may have 17 elements, but that doesn't mean
> you'll have 17 lines. Try
>
>   print join "\n", @temp;
>
> Another issue is line breaks. If you're converting from Windows to
> Unix, or vice versa, Perl may not be seeing your line breaks. Make
> sure your data is correctly formatted for the OS you're using.
>
> Finally, are you sure that every line of your input matches your
> pattern? If not, some elements of @temp will be undefined.
>
> Finally, Perl has a number of techniques to make this process much
> simpler. look at the perldocs for 'foreach', 'push' and array slices
> for starters:
>
>    foreach (@array) {
>        push @temp, (split /:/, $_)[1];
>    }
>
> HTH,
>
> -- jay
> --------------------------------------------------
> This email and attachment(s): [  ] blogable; [ x ] ask first; [  ]
> private and confidential
>
> daggerquill [at] gmail [dot] com
> http://www.tuaw.com  http://www.dpguru.com  http://www.engatiki.org
>
> values of β will give rise to dom!
>



--
Terry Pang

Reply via email to