Stephen Kelly wrote:

> hi there
> 
> i am trying to write a perl script to tidy up any lines in a file that
> don't contain alphabetic characters or single instances of character. i've
> noticed that the even lines are being skipped when read in eg 0,2,4,6 -
> the script is run on window - any ideas?
> 
> # Tidy Glossaries
> 
> #!/usr/bin/perl -w
> 

when you are starting to learn Perl, you should try:

use strict;

in your script.

> open INPUT, "d:/projects/perlscripts/oc_jp.txt"
>     or die "Can't open d:/projects/perlscripts/oc_jp.txt for reading
>     $!\n";
> open OUTPUT, ">>d:/projects/perlscripts/oc_jp_tidy.txt"
>     or die "Can't open d:/projects/perlscripts/oc_jp_tidy.txt $!\n";
> open OUTPUT1, ">>d:/projects/perlscripts/oc_jp_untidy.txt"
>         or die "Can't open d:/projects/perlscripts/oc_jp_untidy.txt $!\n";

you should declare a few variables to hold the name of the files:

my $input = 'd:/projects/perlscripts/oc_jp.txt';
my $tidy  = 'd:/projects/perlscripts/oc_jp_tidy.txt';
my $mess  = 'd:/projects/perlscripts/oc_jp_untidy.txt';

you can then open them accordingly:

open INPUT, $input     or die "Can't open $input: $!\n";
open TIDY,  ">>$tidy"  or die "Can't create $tidy: $!\n";
open MESS,  ">>$mess"  or die "Can't create $mess: $!\n";

notice this improve readability and consequencely maintainability.

> 
> 
> while (<INPUT>)
> {
> 

you got a line from the input file and store it in $_ but you never use $_ 
in your script which means the line is discarded

>
>  chomp($test=<INPUT>);
>

you read another line from the input file and assigne it to $test. at time 
point, you have already read 2 lines. this is most likely the reason why 
you are seeing "even lines". each loop iteration, you read 2 lines.

david
-- 
s$s*$+/<tgmecJ"ntgR"tgjvqpC"vuwL$;$;=qq$
\x24\x5f\x3d\x72\x65\x76\x65\x72\x73\x65
\x24\x5f\x3b\x73\x2f\x2e\x2f\x63\x68\x72
\x28\x6f\x72\x64\x28\x24\x26\x29\x2d\x32
\x29\x2f\x67\x65\x3b\x70\x72\x69\x6e\x74
\x22\x24\x5f\x5c\x6e\x22\x3b\x3b$;eval$;

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to