S
Sim
Hi! Thanks for looking at my problem. I have a problem with joining 2
strings together.
Here is the problem:
I read a file into perl line by line. Each line becomes a string
element in an array. I need to recognize the first, second and third
elements of the array and join them on a single line in the output;
then join the fourth,fifth and sixth elements on the second line. My
inital plan was to use the join() function, but I had problems. The
join function does not join 2 strings on the same line. Can someone
help?(Pardon me if this is supposed to be an easy problem. I am new to
Perl)
My current stage:
my $n;
$n= 1;
open (FILE, 'sample.out');
while (defined ($_ = <FILE>)){
if ($n < 4){
$array[$n] = $_;
print join(' ',$array[$n], $array[$n+1]);#does not
work
print join(' ',@array); #does not work too
$n = $n +1 ;
}
else {
print $_;
print "time for next line";
$n =1;
}
}
close FILE;
strings together.
Here is the problem:
I read a file into perl line by line. Each line becomes a string
element in an array. I need to recognize the first, second and third
elements of the array and join them on a single line in the output;
then join the fourth,fifth and sixth elements on the second line. My
inital plan was to use the join() function, but I had problems. The
join function does not join 2 strings on the same line. Can someone
help?(Pardon me if this is supposed to be an easy problem. I am new to
Perl)
My current stage:
my $n;
$n= 1;
open (FILE, 'sample.out');
while (defined ($_ = <FILE>)){
if ($n < 4){
$array[$n] = $_;
print join(' ',$array[$n], $array[$n+1]);#does not
work
print join(' ',@array); #does not work too
$n = $n +1 ;
}
else {
print $_;
print "time for next line";
$n =1;
}
}
close FILE;