Hi,
I have 4 files that I would like to combine side by side and the seperater is tab in these four files. I also would like to have the output file to be tab delimited. All 4 files have the same legnth.
I wrote the following script where I get an error message at the "k" loop. It does not understand "$#L$s" . what I would like is to print @L1 followed by @L2, @L3, and @L4 side by side with tab as a deliminator. - #!/usr/bin/perl _w
-
-
-
open(data1, "data1.txt") || die "Can not open the file\n";
-
open(data2, "data2.txt") || die "Can not open the file\n";
-
open(data3, "data3.txt") || die "Can not open the file\n";
-
open(data4, "data4.txt") || die "Can not open the file\n";
-
open(outdata, ">combine.txt") || die "Can not open the file\n";
-
-
-
@file1=<data1>;
-
@file2=<data2>;
-
@file3=<data3>;
-
@file4=<data4>;
-
-
-
for($i=0; $i<=$#file1; $i++){
-
-
-
## Printing the data ##
-
-
$L1=$file1[$i];
-
chomp $L1;
-
@L1=split(/\t/, $L1);
-
-
$L2=$file2[$i];
-
chomp $L2;
-
@L2=split(/\t/, $L2);
-
-
$L3=$file3[$i];
-
chomp $L3;
-
@L3=split(/\t/, $L3);
-
-
$L4=$file4[$i];
-
chomp $L4;
-
@L4=split(/\t/, $L4);
-
-
for ($s=1; $s<=4; $s++){
-
-
for ($k=1; $k <= $#L$s ; $k++){
-
-
print outdata "\t$L$s[$k]";
-
-
} # end for k
-
}# end for s
-
-
-
print outdata "\n";
-
-
} # end for i
-
-
close(data1);
-
close(data2);
-
close(data3);
-
close(data4);
7 5170
Yea, this will not work: $#L$s
L is the first character in the name of an array, like @L1, @L2, @L3, @L4. Perl will not interpret that as the name of an array: L$s, that is just the letter L followed by a number, it is not a pointer to the array @L1, @L2, @L3, @L4.
Is this school work ?
Hi Kevin,
Could you debug it and send it to us. your answer is not clear to me.
Thanks.
Hamid
Hi Kevin,
Could you debug it and send it to us. your answer is not clear to me.
Thanks.
Hamid
Define...."us"! Are you and the original poster working together on this? Kevin asked if this is school work and that question has not been answered as of yet.
It is against this sites policy to provide you with the answers to your school work, but we can guide you in the right direction.
Regards,
Jeff
Hi Jeff,
No it is not a school work. I am just learning Perl by myself because I needed for my new job. So it would be helpful if I can fix the bug of that script. I was diging into book whole day and I am just confused now.
Thanks for the help.
Hamid
Define...."us"! Are you and the original poster working together on this? Kevin asked if this is school work and that question has not been answered as of yet.
It is against this sites policy to provide you with the answers to your school work, but we can guide you in the right direction.
Regards,
Jeff
By Saying us I meant the whole pepole who have the same probelem.
Thanks
I can't really understand how you are trying to combine all the lines of the four files into one but maybe something like this will work (untested code): -
#!/usr/bin/perl
-
use strict;
-
use warnings;
-
-
open(data1, "data1.txt") || die "Can not open the file\n";
-
open(data2, "data2.txt") || die "Can not open the file\n";
-
open(data3, "data3.txt") || die "Can not open the file\n";
-
open(data4, "data4.txt") || die "Can not open the file\n";
-
open(outdata, ">combine.txt") || die "Can not open the file\n";
-
-
while(<data1>){
-
my @lines = ($_, scalar <data2> ,scalar <data3>, scalar <data4>);
-
chomp (@lines)
-
print outdata @lines,"\n";
-
}
-
close(data1);
-
close(data2);
-
close(data3);
-
close(data4);
-
close(outdata);
-
if it is c,c++, or java i would've helped you
good luck
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Knighterrant |
last post by:
How to combine multiple xml files into a single one, or split an xml
file into multiple files using xslt?
|
by: PZWU |
last post by:
How can I build a big XML file by appending a few smaller
xml files in C#?
Below is what I've been trying:
/* FileString.xml is the path and name string of the big
xml file*/
XmlTextWriter...
|
by: :) |
last post by:
How to combine serveral large .txt files in C# without using MS command
line. Thanks!!
|
by: amy |
last post by:
Hi, all:
> i am a new end user of access, now I have many excel files need to
> import to One table in access (combine all excel files into one table
> in excel). In excel files, some columns will...
|
by: Sergio |
last post by:
Hello everybody.
Somebody has given me nine files with some data
for the years 1997, 1998, ... , 2005. They are 9 different
mdb files. Each one has many tables, forms, and other things.
But all...
|
by: kumar_ps |
last post by:
I am using vb6.0 here i am using "tif" files my program is i am keeping some tif files in a folder. when i run the program that all the tif files combine one file. i mean suppose we take 4tif files...
|
by: Rodjk #613 |
last post by:
Hello,
I am working with a database that is in use in several locations.
The structure of the databases are identical, but the data is
different.
I am tasked with combining the data into one...
|
by: johnqsmith |
last post by:
Problem background:
gcc v 4.1
2 .cpp files, 2 .h files
Files:
main.cpp
a.cpp
a.h
b.h
|
by: PDSTAR |
last post by:
Hello,
Any help would be much appreciated. I have a directory of ~2000 tab delimited .txt files. I would like to combine all these files (append to the last blank row) into a master file. The one...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |