On Feb 11, 2008 3:11 PM,  <[EMAIL PROTECTED]> wrote:
> Hi,
>     I am learning to print two arrays in a single file but unable to
> do. So, I am printing it in two files. Any ideas
>
> # Populating the arrays @alphaid and @betaid
> foreach my $line (@File1)
>      {
>         if ($line =~ /^AC/)
>           {
>             $line =~ s/^AC\s*//;
>               @alphaid = $line;
>               push(@alphaid,$_);
>           }
>
>         if ($line =~ /^DR/)
>            {
>             $line =~ s/^DR\s*//;
>               @betaid = $line;
>               push(@betaid,$_);
>            }
>      }
>
> #Printing the arrays in two files. Here I would like to have them in a
> single with tab character separating the #arrays such as
> # alphaid[1] \t  betaid[1]
> # alphaid[1] \t  betaid[2]
> # and so on
>
>          foreach $alphaid (@alphaid)
>               {
>               open (MYFILEG, '>>f1.txt');
>               print MYFILEG @alpha;
>               close (MYFILEG);
>                }
>
>         foreach $betaid (@betaid)
>              {
>               open (MYFILEE, '>>f2.txt');
>               print MYFILEE @betaid;
>               close (MYFILEE);
>            }
>
> any help will be appreciated.
> -K
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> http://learn.perl.org/
>
>
>

If you want to print out only pairs you can use the code below.  If
you want to print out all of the items in the the longer array, then
change the <= to >=

#!/usr/bin/perl

use strict;
use warnings;

my @a = qw<a b c d e>;
my @b = (1, 2, 3);

my $len = @a <= @b ? @a : @b;

for my $i (0 .. $len - 1) {
        print "$a[$i]\t$b[$i]\n";
}

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to