Hi,
I need to join every alternate line in a file
for eg:input file
output
code i wrote for this
I am gettin the desired output but with the following error
can you please help my understand this error
Thanks
Sam
I need to join every alternate line in a file
for eg:input file
Code:
$ cat abc
abc
def
ghi
jkl
Code:
abc def
ghi jkl
Code:
$ cat add_line.pl
#!/usr/bin/perl -w
my $count=1;
#my $line=undef;
my @mem_line;
my $i=0;
my $x=0;
while(<>)
{
chomp;
$x=$count % 2;
#print "$x $_\n";
if ( $x == 1 )
{
$mem_line[$i] = "$_";
}
else
{
$mem_line[$i - 1] .= " $_\n";
}
$count+=1;
$i+=1;
}
print "@mem_line";
Code:
./add_line.pl abc
Use of uninitialized value in join or string at ./add_line.pl line 26, <> line 4.
abc def
ghi jkl
Thanks
Sam