Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I concatenate files 1

Status
Not open for further replies.

babs

Programmer
Dec 29, 2000
7
US
I am a novice in writing Perl script.
How can I concatenate two files. The files are created in separate runs. I need to send the files out as one file.

Thanks for your time and help in advance.

Babs
 
there are easily a hundred ways to do this.

is the file data stored as a scalar or as an array? if it's a scalar, the scalar concatenation operator is '.', so just do:[tt]
my $two_files = $file1 . $file2;
[/tt]
if they are arrays, you can join two arrays with the 'push' function:[tt]
push @two_files, @file1, @file2;[/tt]


really, though, you don't need to do either of these - when you open up the file to be printed, just print in both sets of data.

or, after you've already print into the file the first time and closed it, open it up for concatenation ("open FILE, '>>file.ext'") and print in the second one.

hope this helps "If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."
 
If you are running on a *nix system you can also use the systems "cat" command to concatentate two files and create a new file:
Code:
system "cat file1 file2 >file3";
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
yet another perspective....
If you are running on a *nix system and all you want to do is string two files together, then don't use Perl. Just use the OS command.....

prompt# cat file1 file2 >new_file

HTH


keep the rudder amid ship and beware the odd typo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top