I met an interesting problem recently and am expecting your kind advice.

my input file (for_test) is like as follows. I wish add a ">" to the first line (before the word blue) and remove ">" at the last line.

# ---begining of the file, this line is not included in the file---#
blue
sky
skirt
sea
>white
paper
flower
mine
>red
face
flower
>milk_white
milk
ivory
>green
grand
tree
>
#___________END,this line is not included in the file__________#

my program is as this :

# to add the > to the first line and remove > at last line

#!/usr/bin/perl -w
use strict;

my $infile = for_test;

open (INPUT, "$infile") || die " can not open $infile";
open OUTPUT, ">test.res" ||die "can not open test.res";

my @items = <INPUT>;

my $item = ">$items[0]";
shift (@items);
unshift (@items, $item);
pop (@items);
chomp ($items[-1]);
print OUTPUT "@items\n";

close OUTPUT;
close INPUT;
#_______END_________#



After execute the program. The result was not as what I expected since the ">" add a new column at the left side. Iin the first line ">blue" , ">" is added by the program. But it also add a new column to the file at the left side. This is not what I expected becuase this also add a space to other element at the left side when print it.

>blue
 sky
 skirt
 sea
 >white
 paper
 flower
 mine
 >red
 face
 flower
 >milk_white
 milk
 ivory
 >green
 grand
 tree





--
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