Hi lina On Mon, May 7, 2012 at 8:36 AM, lina <lina.lastn...@gmail.com> wrote:
> Hi, > > I have two files, one with > > 3 > 2 > 1 > > another is: > > 3 1 > 3 2 > 6 3 > > How can I insert the first file into the middle of the second file, > This is one way to do it: #!/usr/bin/perl use warnings; use strict; my $part1 = get_data( $ARGV[0] ); # get f1.txt from CLI my $part2 = get_data( $ARGV[1] ); # get f2.txt from CLI my $cot = () = @{$part1}; foreach ( 0 .. ( $cot - 1 ) ) { my @rec = split /\s+/, $part2->[$_]; print $rec[0], " ", $part1->[$_], " ", $rec[1], $/; } sub get_data { my ($file) = @_; my $arr_ref = []; open my $fh, '<', $file or die "can't open this file: $!"; while (<$fh>) { chomp; push @$arr_ref, $_; } close $fh or die "can't close file:$!"; return $arr_ref; } > > Thanks ahead for your suggestions, > > Best regards, > > -- Tim