From Ganesh.Shankar at RoswellPark.org Mon Jul 4 12:33:11 2005 From: Ganesh.Shankar at RoswellPark.org (Shankar, Ganesh) Date: Mon, 4 Jul 2005 15:33:11 -0400 Subject: [Buffalo-pm] Question: How to iterate through 2 arrays and merge columns Message-ID: <6FF91AE4F1DC7743A6466E334EB865AE02EB023C@VERITY.roswellpark.org> Hello All, I'm learning perl to process microarray data and mostly I've found it very useful. However, I've come to a problem that I haven't been able to solve. Background: One experiment generates two raw (tab-delimited)data files. The order of the lines in both these files are identical. I need to grab 4 columns from each file and horizontally merge them in the resulting results file. I've opened,read,split and pushed the elements into two arrays in their own foreach loops. push(our @red_elements, ($red_items[6], "\t", $red_items[7], "\t", $red_items[8], "\t", $red_items[9], "\n" ) ); } #end foreach my $red_line push(our @green_elements, ($green_items[6], "\t", $green_items[7], "\t", green_items[8], "\t", $green_items[9], "\n" ) ); } #end foreach my $red_line What I need in the final file is : ($red_items[6], "\t", $red_items[7], "\t", $red_items[8], "\t", $red_items[9], "\t", $green_items[6], "\t", $green_items[7], "\t", green_items[8], "\t", $green_items[9], "\n" How do I iterate through two arrays at once? I've tried the Array::Each module, but I couldn't extend the example in the synopsis to multiple columns. Thanks for any help. -Ganesh This email message may contain legally privileged and/or confidential information. If you are not the intended recipient(s), or the employee or agent responsible for the delivery of this message to the intended recipient(s), you are hereby notified that any disclosure, copying, distribution, or use of this email message is prohibited. If you have received this message in error, please notify the sender immediately by e-mail and delete this email message from your computer. Thank you. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/ms-tnef Size: 3052 bytes Desc: not available Url : http://mail.pm.org/pipermail/buffalo-pm/attachments/20050704/cc445547/attachment.bin From cbrandt at buffalo.edu Mon Jul 4 14:56:02 2005 From: cbrandt at buffalo.edu (Jim Brandt) Date: Mon, 4 Jul 2005 17:56:02 -0400 Subject: [Buffalo-pm] Question: How to iterate through 2 arrays and merge columns In-Reply-To: <6FF91AE4F1DC7743A6466E334EB865AE02EB023C@VERITY.roswellpark.org> References: <6FF91AE4F1DC7743A6466E334EB865AE02EB023C@VERITY.roswellpark.org> Message-ID: <7873C86B-EB59-45F9-9F54-D5791BBB824B@buffalo.edu> If the arrays are truly identical, you can iterate through either one using the C-style for loop and grab one item at a time from each. It would look something like (untested): for ( my $i=0; $i <= $#red_items; $i++ ){ print OUTFILE $red_items[$i], $green_items[$i]; } This style for loop starts at the initial value of $i, iterates as long as the middle condition is true, and increments based on the last expression. In this case, it will iterate one number at a time. The $#red_items variable holds the last index of the array @red_items, so it will iterate to the last element of the array. On Jul 4, 2005, at 3:33 PM, Shankar, Ganesh wrote: > > Hello All, > > I'm learning perl to process microarray data and mostly I've found it > very useful. However, I've come to a problem that I haven't been able > to solve. > > Background: One experiment generates two raw (tab-delimited)data > files. > The order of the lines in both these files are identical. I need to > grab 4 columns from each file and horizontally merge them in the > resulting results file. > > I've opened,read,split and pushed the elements into two arrays in > their > own foreach loops. > > push(our @red_elements, > ($red_items[6], "\t", $red_items[7], "\t", > $red_items[8], "\t", $red_items[9], "\n" > ) > ); > } #end foreach my $red_line > > push(our @green_elements, > ($green_items[6], "\t", $green_items[7], "\t", > green_items[8], "\t", $green_items[9], "\n" > ) > ); > } #end foreach my $red_line > > What I need in the final file is : > > ($red_items[6], "\t", $red_items[7], "\t", > $red_items[8], "\t", $red_items[9], "\t", > $green_items[6], "\t", $green_items[7], "\t", > green_items[8], "\t", $green_items[9], "\n" > > How do I iterate through two arrays at once? I've tried the > Array::Each > module, but I couldn't extend the example in the synopsis to multiple > columns. > > Thanks for any help. > > -Ganesh > > ========================================== Jim Brandt Administrative Computing Services University at Buffalo From Ganesh.Shankar at RoswellPark.org Tue Jul 5 06:17:23 2005 From: Ganesh.Shankar at RoswellPark.org (Shankar, Ganesh) Date: Tue, 5 Jul 2005 09:17:23 -0400 Subject: [Buffalo-pm] Question: How to iterate through 2 arrays and merge columns Message-ID: <6FF91AE4F1DC7743A6466E334EB865AE0BF84BF4@VERITY.roswellpark.org> Thanks for your reply. The two arrays each hold 4 elements per line. There are approx. 18,000 lines per file. The final line should contain 8 elements, after processing. The first 4 would be from @red_elements and the second 4 would be from @green_elements. So, in your solution, would $red_items[$i] represent the entire line consisting of all 4 elements? -Ganesh -----Original Message----- From: Jim Brandt [mailto:cbrandt at buffalo.edu] Sent: Monday, July 04, 2005 5:56 PM To: Shankar, Ganesh Cc: buffalo-pm at pm.org Subject: Re: Question: How to iterate through 2 arrays and merge columns If the arrays are truly identical, you can iterate through either one using the C-style for loop and grab one item at a time from each. It would look something like (untested): for ( my $i=0; $i <= $#red_items; $i++ ){ print OUTFILE $red_items[$i], $green_items[$i]; } This style for loop starts at the initial value of $i, iterates as long as the middle condition is true, and increments based on the last expression. In this case, it will iterate one number at a time. The $#red_items variable holds the last index of the array @red_items, so it will iterate to the last element of the array. On Jul 4, 2005, at 3:33 PM, Shankar, Ganesh wrote: > > Hello All, > > I'm learning perl to process microarray data and mostly I've found it > very useful. However, I've come to a problem that I haven't been able > to solve. > > Background: One experiment generates two raw (tab-delimited)data > files. > The order of the lines in both these files are identical. I need to > grab 4 columns from each file and horizontally merge them in the > resulting results file. > > I've opened,read,split and pushed the elements into two arrays in > their > own foreach loops. > > push(our @red_elements, > ($red_items[6], "\t", $red_items[7], "\t", > $red_items[8], "\t", $red_items[9], "\n" > ) > ); > } #end foreach my $red_line > > push(our @green_elements, > ($green_items[6], "\t", $green_items[7], "\t", > green_items[8], "\t", $green_items[9], "\n" > ) > ); > } #end foreach my $red_line > > What I need in the final file is : > > ($red_items[6], "\t", $red_items[7], "\t", > $red_items[8], "\t", $red_items[9], "\t", > $green_items[6], "\t", $green_items[7], "\t", > green_items[8], "\t", $green_items[9], "\n" > > How do I iterate through two arrays at once? I've tried the > Array::Each > module, but I couldn't extend the example in the synopsis to multiple > columns. > > Thanks for any help. > > -Ganesh > > ========================================== Jim Brandt Administrative Computing Services University at Buffalo This email message may contain legally privileged and/or confidential information. If you are not the intended recipient(s), or the employee or agent responsible for the delivery of this message to the intended recipient(s), you are hereby notified that any disclosure, copying, distribution, or use of this email message is prohibited. If you have received this message in error, please notify the sender immediately by e-mail and delete this email message from your computer. Thank you. From dmagnuszewski at mandtbank.com Tue Jul 5 07:02:01 2005 From: dmagnuszewski at mandtbank.com (DANIEL MAGNUSZEWSKI) Date: Tue, 05 Jul 2005 10:02:01 -0400 Subject: [Buffalo-pm] Question: How to iterate through 2 arrays andmerge columns Message-ID: For what you wanted, it looks like $red_items[$i] would be the four red elements. If I were to go about doing what you're trying to accomplish, I would: # Not Tested my @red_elements = `/bin/cat file1 | awk \'{print "$4 $5 $6 $7"}\'`; my @green_elements = `/bin/cat file2 | awk \'{print "$4 $5 $6 $7"}\'`; open OUTFILE, ">outputfile" or die "Can't open file\n"; for ( my $i=0; $i <= $#red_elements; $i++ ){ print OUTFILE $red_elements[$i], $green_elements[$i]; } Hope this helps. Daniel Magnuszewski CCNA M & T Bank dmagnuszewski at mandtbank.com >>> "Shankar, Ganesh" 07/05/05 9:17 AM >>> Thanks for your reply. The two arrays each hold 4 elements per line. There are approx. 18,000 lines per file. The final line should contain 8 elements, after processing. The first 4 would be from @red_elements and the second 4 would be from @green_elements. So, in your solution, would $red_items[$i] represent the entire line consisting of all 4 elements? -Ganesh -----Original Message----- From: Jim Brandt [mailto:cbrandt at buffalo.edu] Sent: Monday, July 04, 2005 5:56 PM To: Shankar, Ganesh Cc: buffalo-pm at pm.org Subject: Re: Question: How to iterate through 2 arrays and merge columns If the arrays are truly identical, you can iterate through either one using the C-style for loop and grab one item at a time from each. It would look something like (untested): for ( my $i=0; $i <= $#red_items; $i++ ){ print OUTFILE $red_items[$i], $green_items[$i]; } This style for loop starts at the initial value of $i, iterates as long as the middle condition is true, and increments based on the last expression. In this case, it will iterate one number at a time. The $#red_items variable holds the last index of the array @red_items, so it will iterate to the last element of the array. On Jul 4, 2005, at 3:33 PM, Shankar, Ganesh wrote: > > Hello All, > > I'm learning perl to process microarray data and mostly I've found it > very useful. However, I've come to a problem that I haven't been able > to solve. > > Background: One experiment generates two raw (tab-delimited)data > files. > The order of the lines in both these files are identical. I need to > grab 4 columns from each file and horizontally merge them in the > resulting results file. > > I've opened,read,split and pushed the elements into two arrays in > their > own foreach loops. > > push(our @red_elements, > ($red_items[6], "\t", $red_items[7], "\t", > $red_items[8], "\t", $red_items[9], "\n" > ) > ); > } #end foreach my $red_line > > push(our @green_elements, > ($green_items[6], "\t", $green_items[7], "\t", > green_items[8], "\t", $green_items[9], "\n" > ) > ); > } #end foreach my $red_line > > What I need in the final file is : > > ($red_items[6], "\t", $red_items[7], "\t", > $red_items[8], "\t", $red_items[9], "\t", > $green_items[6], "\t", $green_items[7], "\t", > green_items[8], "\t", $green_items[9], "\n" > > How do I iterate through two arrays at once? I've tried the > Array::Each > module, but I couldn't extend the example in the synopsis to multiple > columns. > > Thanks for any help. > > -Ganesh > > ========================================== Jim Brandt Administrative Computing Services University at Buffalo This email message may contain legally privileged and/or confidential information. If you are not the intended recipient(s), or the employee or agent responsible for the delivery of this message to the intended recipient(s), you are hereby notified that any disclosure, copying, distribution, or use of this email message is prohibited. If you have received this message in error, please notify the sender immediately by e-mail and delete this email message from your computer. Thank you. _______________________________________________ Buffalo-pm mailing list Buffalo-pm at pm.org http://mail.pm.org/mailman/listinfo/buffalo-pm From dmagnuszewski at mandtbank.com Tue Jul 5 07:08:16 2005 From: dmagnuszewski at mandtbank.com (DANIEL MAGNUSZEWSKI) Date: Tue, 05 Jul 2005 10:08:16 -0400 Subject: [Buffalo-pm] Question: How to iterate through 2 arraysandmerge columns Message-ID: Actually, after I sent this in, I realized that the pipe in the external command would not work. Does anyone know how to properly connect the pipes? >>> "DANIEL MAGNUSZEWSKI" 07/05/05 10:02 AM >>> For what you wanted, it looks like $red_items[$i] would be the four red elements. If I were to go about doing what you're trying to accomplish, I would: # Not Tested my @red_elements = `/bin/cat file1 | awk \'{print "$4 $5 $6 $7"}\'`; my @green_elements = `/bin/cat file2 | awk \'{print "$4 $5 $6 $7"}\'`; open OUTFILE, ">outputfile" or die "Can't open file\n"; for ( my $i=0; $i <= $#red_elements; $i++ ){ print OUTFILE $red_elements[$i], $green_elements[$i]; } Hope this helps. Daniel Magnuszewski CCNA M & T Bank dmagnuszewski at mandtbank.com >>> "Shankar, Ganesh" 07/05/05 9:17 AM >>> Thanks for your reply. The two arrays each hold 4 elements per line. There are approx. 18,000 lines per file. The final line should contain 8 elements, after processing. The first 4 would be from @red_elements and the second 4 would be from @green_elements. So, in your solution, would $red_items[$i] represent the entire line consisting of all 4 elements? -Ganesh -----Original Message----- From: Jim Brandt [mailto:cbrandt at buffalo.edu] Sent: Monday, July 04, 2005 5:56 PM To: Shankar, Ganesh Cc: buffalo-pm at pm.org Subject: Re: Question: How to iterate through 2 arrays and merge columns If the arrays are truly identical, you can iterate through either one using the C-style for loop and grab one item at a time from each. It would look something like (untested): for ( my $i=0; $i <= $#red_items; $i++ ){ print OUTFILE $red_items[$i], $green_items[$i]; } This style for loop starts at the initial value of $i, iterates as long as the middle condition is true, and increments based on the last expression. In this case, it will iterate one number at a time. The $#red_items variable holds the last index of the array @red_items, so it will iterate to the last element of the array. On Jul 4, 2005, at 3:33 PM, Shankar, Ganesh wrote: > > Hello All, > > I'm learning perl to process microarray data and mostly I've found it > very useful. However, I've come to a problem that I haven't been able > to solve. > > Background: One experiment generates two raw (tab-delimited)data > files. > The order of the lines in both these files are identical. I need to > grab 4 columns from each file and horizontally merge them in the > resulting results file. > > I've opened,read,split and pushed the elements into two arrays in > their > own foreach loops. > > push(our @red_elements, > ($red_items[6], "\t", $red_items[7], "\t", > $red_items[8], "\t", $red_items[9], "\n" > ) > ); > } #end foreach my $red_line > > push(our @green_elements, > ($green_items[6], "\t", $green_items[7], "\t", > green_items[8], "\t", $green_items[9], "\n" > ) > ); > } #end foreach my $red_line > > What I need in the final file is : > > ($red_items[6], "\t", $red_items[7], "\t", > $red_items[8], "\t", $red_items[9], "\t", > $green_items[6], "\t", $green_items[7], "\t", > green_items[8], "\t", $green_items[9], "\n" > > How do I iterate through two arrays at once? I've tried the > Array::Each > module, but I couldn't extend the example in the synopsis to multiple > columns. > > Thanks for any help. > > -Ganesh > > ========================================== Jim Brandt Administrative Computing Services University at Buffalo This email message may contain legally privileged and/or confidential information. If you are not the intended recipient(s), or the employee or agent responsible for the delivery of this message to the intended recipient(s), you are hereby notified that any disclosure, copying, distribution, or use of this email message is prohibited. If you have received this message in error, please notify the sender immediately by e-mail and delete this email message from your computer. Thank you. _______________________________________________ Buffalo-pm mailing list Buffalo-pm at pm.org http://mail.pm.org/mailman/listinfo/buffalo-pm _______________________________________________ Buffalo-pm mailing list Buffalo-pm at pm.org http://mail.pm.org/mailman/listinfo/buffalo-pm From dmagnuszewski at mandtbank.com Tue Jul 5 07:12:46 2005 From: dmagnuszewski at mandtbank.com (DANIEL MAGNUSZEWSKI) Date: Tue, 05 Jul 2005 10:12:46 -0400 Subject: [Buffalo-pm] YAPC Message-ID: For those of you who went... How was it? What talks did you go to? What did Larry have to say? From sgriffit at gennum.com Tue Jul 5 07:30:17 2005 From: sgriffit at gennum.com (Shaun Griffith) Date: Tue, 5 Jul 2005 10:30:17 -0400 Subject: [Buffalo-pm] Question: How to iterate through 2 arrays andmerge columns In-Reply-To: <6FF91AE4F1DC7743A6466E334EB865AE0BF84BF4@VERITY.roswellpark.org> Message-ID: <000d01c5816e$112525c0$c417005a@headoffice.gennum.com> You may want something like this: foreach my $i ($i=0;$i<@red;$i+=4) { printf "%s\t" x 8 . "\n", @red[$i..$i+3], at green[$i..$i+3]; } This assumes that you have checked that @red and @green are the same length, and multiples of 4. (Use whatever is appropriate for the "%s" descriptor.) -Shaun > -----Original Message----- > From: buffalo-pm-bounces at pm.org [mailto:buffalo-pm-bounces at pm.org]On > Behalf Of Shankar, Ganesh > Sent: July 5, 2005 9:17 AM > To: Jim Brandt > Cc: buffalo-pm at pm.org > Subject: Re: [Buffalo-pm] Question: How to iterate through 2 arrays > andmerge columns > > > Thanks for your reply. > > The two arrays each hold 4 elements per line. There are > approx. 18,000 > lines per file. The final line should contain 8 elements, after > processing. The first 4 would be from @red_elements and the second 4 > would be from @green_elements. > > So, in your solution, would $red_items[$i] represent the entire line > consisting of all 4 elements? > > -Ganesh > -------------- next part -------------- A non-text attachment was scrubbed... Name: winmail.dat Type: application/ms-tnef Size: 2184 bytes Desc: not available Url : http://mail.pm.org/pipermail/buffalo-pm/attachments/20050705/59f5d5e3/winmail.bin From eye at buffalo.edu Tue Jul 5 07:34:47 2005 From: eye at buffalo.edu (Kevin Eye) Date: Tue, 5 Jul 2005 10:34:47 -0400 Subject: [Buffalo-pm] Question: How to iterate through 2 arraysandmerge columns In-Reply-To: References: Message-ID: I don't understand why your suggestion wouldn't work, Dan. I don't see anything wrong with the pipes. However, all these solutions seem quite inefficient. I think it's simplest to just open both input files at once, read a line from each, and immediately write the new line out like this: open IN1, 'input_1.tab'; open IN2, 'input_2.tab'; open OUT, '>output.tab'; while(1) { $in_1_line = ; $in_2_line = ; last unless defined $in_1_line and defined $in_2_line; # quit when out of input chomp $in_1_line; chomp $in_2_line; @in_1_fields = split "\t", $in_1_line; @in_2_fields = split "\t", $in_2_line; print OUT join("\t", @in_1_fields[0..3], @in_2_fields[0..3])."\n"; } close IN1; close IN2; close OUT; If you want fields other than 1, 2, 3, and 4 of each input file in the output, just change the array indices on the print line. If you always want all the fields, and every line always has the same number of fields, you could even get rid of the splitting and joining and just concatenate $in_1_line and $in_2_line to make it run faster. - Kevin On Jul 5, 2005, at 10:08 AM, DANIEL MAGNUSZEWSKI wrote: > Actually, after I sent this in, I realized that the pipe in the > external > command would not work. Does anyone know how to properly connect the > pipes? > >>>> "DANIEL MAGNUSZEWSKI" 07/05/05 10:02 > AM >>> > For what you wanted, it looks like $red_items[$i] would be the four > red > elements. > > If I were to go about doing what you're trying to accomplish, I would: > > > # Not Tested > my @red_elements = `/bin/cat file1 | awk \'{print "$4 $5 $6 > $7"}\'`; > my @green_elements = `/bin/cat file2 | awk \'{print "$4 $5 $6 $7"}\'`; > > open OUTFILE, ">outputfile" or die "Can't open file\n"; > > for ( my $i=0; $i <= $#red_elements; $i++ ){ > print OUTFILE $red_elements[$i], $green_elements[$i]; > } > > > > Hope this helps. > > Daniel Magnuszewski > CCNA > M & T Bank > dmagnuszewski at mandtbank.com > >>>> "Shankar, Ganesh" 07/05/05 9:17 > AM >>>> > Thanks for your reply. > > The two arrays each hold 4 elements per line. There are approx. > 18,000 > lines per file. The final line should contain 8 elements, after > processing. The first 4 would be from @red_elements and the second 4 > would be from @green_elements. > > So, in your solution, would $red_items[$i] represent the entire line > consisting of all 4 elements? > > -Ganesh > > -----Original Message----- > From: Jim Brandt [mailto:cbrandt at buffalo.edu] > Sent: Monday, July 04, 2005 5:56 PM > To: Shankar, Ganesh > Cc: buffalo-pm at pm.org > Subject: Re: Question: How to iterate through 2 arrays and merge > columns > > If the arrays are truly identical, you can iterate through either one > > using the C-style for loop and grab one item at a time from each. It > would look something like (untested): > > for ( my $i=0; $i <= $#red_items; $i++ ){ > print OUTFILE $red_items[$i], $green_items[$i]; > } > > This style for loop starts at the initial value of $i, iterates as > long as the middle condition is true, and increments based on the > last expression. In this case, it will iterate one number at a time. > > The $#red_items variable holds the last index of the array > @red_items, so it will iterate to the last element of the array. > > > On Jul 4, 2005, at 3:33 PM, Shankar, Ganesh wrote: > >> >> Hello All, >> >> I'm learning perl to process microarray data and mostly I've found > it >> very useful. However, I've come to a problem that I haven't been > able >> to solve. >> >> Background: One experiment generates two raw (tab-delimited)data >> files. >> The order of the lines in both these files are identical. I need > to >> grab 4 columns from each file and horizontally merge them in the >> resulting results file. >> >> I've opened,read,split and pushed the elements into two arrays in >> their >> own foreach loops. >> >> push(our @red_elements, >> ($red_items[6], "\t", $red_items[7], "\t", >> $red_items[8], "\t", $red_items[9], "\n" >> ) >> ); >> } #end foreach my $red_line >> >> push(our @green_elements, >> ($green_items[6], "\t", $green_items[7], "\t", >> green_items[8], "\t", $green_items[9], "\n" >> ) >> ); >> } #end foreach my $red_line >> >> What I need in the final file is : >> >> ($red_items[6], "\t", $red_items[7], "\t", >> $red_items[8], "\t", $red_items[9], "\t", >> $green_items[6], "\t", $green_items[7], "\t", >> green_items[8], "\t", $green_items[9], "\n" >> >> How do I iterate through two arrays at once? I've tried the >> Array::Each >> module, but I couldn't extend the example in the synopsis to > multiple >> columns. >> >> Thanks for any help. >> >> -Ganesh >> >> > > ========================================== > Jim Brandt > Administrative Computing Services > University at Buffalo > > > > This email message may contain legally privileged and/or confidential > information. If you are not the intended recipient(s), or the > employee > or agent responsible for the delivery of this message to the intended > recipient(s), you are hereby notified that any disclosure, copying, > distribution, or use of this email message is prohibited. If you have > received this message in error, please notify the sender immediately > by > e-mail and delete this email message from your computer. Thank you. > _______________________________________________ > Buffalo-pm mailing list > Buffalo-pm at pm.org > http://mail.pm.org/mailman/listinfo/buffalo-pm > > > _______________________________________________ > Buffalo-pm mailing list > Buffalo-pm at pm.org > http://mail.pm.org/mailman/listinfo/buffalo-pm > > > _______________________________________________ > Buffalo-pm mailing list > Buffalo-pm at pm.org > http://mail.pm.org/mailman/listinfo/buffalo-pm > -- Kevin Eye Web Applications Developer Creative Services and Marketing University at Buffalo 330 Crofts Hall Buffalo, NY 14260 eye at buffalo.edu phone (716) 645-5000 x1435 fax (716) 645-3765 From john at perlwolf.com Tue Jul 5 08:03:00 2005 From: john at perlwolf.com (John Macdonald) Date: Tue, 5 Jul 2005 11:03:00 -0400 Subject: [Buffalo-pm] Question: How to iterate through 2 arraysandmerge columns In-Reply-To: References: Message-ID: <20050705150300.GA13829@lupus.perlwolf.com> On Tue, Jul 05, 2005 at 10:34:47AM -0400, Kevin Eye wrote: > I don't understand why your suggestion wouldn't work, Dan. I don't see > anything wrong with the pipes. aside from the pointless use of cat... Any time that you have a command pipeline: cat file | foo [args] you can run just the single command instead: foo < file [args] For many commands, like the instance of awk that is being discussed, you can give a file (list) as part of the arguments so you (often) don't need the '<' in front of the filename. So: my @red_elements = `/bin/cat file1 | awk \'{print "$4 $5 $6 $7"}\'`; my @green_elements = `/bin/cat file2 | awk \'{print "$4 $5 $6 $7"}\'`; can be written: my @red_elements = `awk \'{print "$4 $5 $6 $7"}\' file1`; my @green_elements = `awk \'{print "$4 $5 $6 $7"}\' file2`; I was just about to write the same sort of code as Kevin to do the whole job in Perl, reading the files a line at a time instead of slurping everything at once. (Slurping is useful until you use it with an input file that is too big - then you start swapping and slow down to a crawl with a program that "always ran fine before". When this happens months or years after you wrote the original script, it takes a while to figure out what's going on - you'll often spend a lot of time looking for problems outside the script before realizing that this has been a potential problem that has been lurking all along and not some new circumstance.) -- -- From eye at buffalo.edu Tue Jul 5 08:24:58 2005 From: eye at buffalo.edu (Kevin Eye) Date: Tue, 5 Jul 2005 11:24:58 -0400 Subject: [Buffalo-pm] YAPC In-Reply-To: References: Message-ID: <71662fc50d7d3e0406fc409fc644c1bd@buffalo.edu> >> For those of you who went... >> >> How was it? What talks did you go to? What did Larry have to say? It looks like speakers will be uploading their slides and possibly audio and video to an interactive version of the schedule here: http://hew.ca/cgi-bin/page.pl?Day=Day%201 Also, there were "official" video recordings of most talks, which, for speakers who have given consent, will be available for download in a while after they've been processed. Larry spoke about community building, particularly about how it's full of contradictions. It was full of metaphors (his usual style) for community structures, including lots of pictures of carefully engineered structures and neatly stacked stones illustrating hierarchy and balance, followed by the open source geek version of community -- a thousand jagged rocks dumped out next to each other. Allison Randal gave status updates on perl 5 and perl 6, and also mentioned that the perl foundation is using a new onion logo because the camel, being owned by O'Reilly, isn't legally appropriate in many situations. It looks like this: http://i.perl.org/powered/perlpowered.png There should be usage guidelines on the perl foundation web site soon. Damian Conway was notably absent from the conference, making for a less-than-spectacular closing keynote where Chip Salzenberg (working on Parrot) described how perl is more like Krav Maga than Akido. Damian had once proposed that perl has all the grace and beauty of Akido. Chip says that if we must use martial arts metaphores, Krav Maga is blunt, direct, and has no rules. He then a-little-too-seamlessly transitioned to a monologue about how he's getting seriously harassed by his (former) employer. More info here: http://geeksunite.net/ Other highlights for me included learning that perl 6 development is going in every direction at once. (How's that for TMTOWTDI?) Parrot is the virtual machine that will run perl 6. Ideally, it will also be an ideal virtual machine to run Python, Ruby, and who knows what other kinds of languages. However, it will not be the only way to run perl 6. PGE (Perl Grammar Engine) will be the official compiler for perl, and will compile and optimize for the Parrot VM, but may also be able to output for other targets. PUGS is a prototype implementation of perl 6 which will help to experiment with the new syntax and features, and will stick around as an alternate compiler and runtime for perl 6 experimentation. There was also a lot of talk about testing (as usual), including discussion of several useful-looking modules: Test::Differences, Test::LongString, and Test::Deep for better comparisons in testing; Test::WWW::Mechanize for HTML testing and HTTP::Recorder to make WWW::Mechanize scripts; and Test::HTML::Tidy and Test::HTML::Lint for HTML validation. I could cover testing at one of our meetings as a part of writing a module when that talk comes up. There was also plenty about databases, including a lot of buzz about sql-lite and DBD::SQL::Lite, a full SQL database that runs from one data file and needs no separate server process. Other cool database modules: SQL::Translator for translating between different flavors of SQL (Oracle, MySQL, Postgres, etc.); Class::DBI::Loader and Class::DBI::Loader::Relationship for automatically setting up your Class::DBI-based perl module from existing database tables and relationships; and Class::DBI::AsXML, Class::DBI::FromCGI, and Class::DBI::AsForm. - Kevin On Jul 5, 2005, at 10:12 AM, DANIEL MAGNUSZEWSKI wrote: > For those of you who went... > > How was it? What talks did you go to? What did Larry have to say? > > > > _______________________________________________ > Buffalo-pm mailing list > Buffalo-pm at pm.org > http://mail.pm.org/mailman/listinfo/buffalo-pm > -- Kevin Eye Web Applications Developer Creative Services and Marketing University at Buffalo 330 Crofts Hall Buffalo, NY 14260 eye at buffalo.edu phone (716) 645-5000 x1435 fax (716) 645-3765 From Ganesh.Shankar at RoswellPark.org Tue Jul 5 19:33:32 2005 From: Ganesh.Shankar at RoswellPark.org (Shankar, Ganesh) Date: Tue, 5 Jul 2005 22:33:32 -0400 Subject: [Buffalo-pm] Question: How to iterate through 2 arrays andmerge columns Message-ID: <6FF91AE4F1DC7743A6466E334EB865AE02EB0240@VERITY.roswellpark.org> Hello all, Thanks for your pointers. Since I'm trapped in the windows world, I didn't try the pipe/awk route. Your suggestions were on the right track but maybe I wasn't clear as to what I wanted. I need 4 cols from red followed by 4 cols from green. The following code gives me 4 pairs of red(no space)green(tab)(tab). I tried: for (my $j=0;$j<=$#red_items;$j++){ push(@intermediate, $red_items[$j],$green_items[$j]); } print OUTFILE @intermediate; What results is: $red_items[6](no space)$green_items[6](2 tabs)$red_items[7](no space)$green_items[7] (2 tabs)$red_items[8](no space)$green_items[8](2tabs)$red_items[9](nospace)$green_items[9] What I need is: $red_items[6], tab, $red_items[7], tab, $red_items[8], tab, $red_items[9], tab, $green_items[6], tab, $green_items[7], tab, green_items[8], tab, $green_items[9], nextline Next, I tried to process @intermediate to the format I wanted. foreach $intermediate (@intermediate) { our @all_items = split('\t', $inter); print OUTFILE $all_items[0], "\t",$all_items[2], "\t",$all_items[4], "\t", $all_items[6], "\t",$all_items[1], "\t",$all_items[3], "\t",$all_items[5], "\t", $all_items[7], "\n"; } but that ended up being a bigger mess than before. Also, I'm getting one of those irritating "uninitialized value at " the print OUTFILE line. Where do I go from here? Thanks for all the help. -Ganesh -----Original Message----- From: DANIEL MAGNUSZEWSKI [mailto:dmagnuszewski at mandtbank.com] Sent: Tue 7/5/2005 10:02 AM To: cbrandt at buffalo.edu; Shankar, Ganesh Cc: buffalo-pm at pm.org Subject: Re: [Buffalo-pm] Question: How to iterate through 2 arrays andmerge columns For what you wanted, it looks like $red_items[$i] would be the four red elements. If I were to go about doing what you're trying to accomplish, I would: # Not Tested my @red_elements = `/bin/cat file1 | awk \'{print "$4 $5 $6 $7"}\'`; my @green_elements = `/bin/cat file2 | awk \'{print "$4 $5 $6 $7"}\'`; open OUTFILE, ">outputfile" or die "Can't open file\n"; for ( my $i=0; $i <= $#red_elements; $i++ ){ print OUTFILE $red_elements[$i], $green_elements[$i]; } Hope this helps. Daniel Magnuszewski CCNA M & T Bank dmagnuszewski at mandtbank.com >>> "Shankar, Ganesh" 07/05/05 9:17 AM >>> Thanks for your reply. The two arrays each hold 4 elements per line. There are approx. 18,000 lines per file. The final line should contain 8 elements, after processing. The first 4 would be from @red_elements and the second 4 would be from @green_elements. So, in your solution, would $red_items[$i] represent the entire line consisting of all 4 elements? -Ganesh -----Original Message----- From: Jim Brandt [mailto:cbrandt at buffalo.edu] Sent: Monday, July 04, 2005 5:56 PM To: Shankar, Ganesh Cc: buffalo-pm at pm.org Subject: Re: Question: How to iterate through 2 arrays and merge columns If the arrays are truly identical, you can iterate through either one using the C-style for loop and grab one item at a time from each. It would look something like (untested): for ( my $i=0; $i <= $#red_items; $i++ ){ print OUTFILE $red_items[$i], $green_items[$i]; } This style for loop starts at the initial value of $i, iterates as long as the middle condition is true, and increments based on the last expression. In this case, it will iterate one number at a time. The $#red_items variable holds the last index of the array @red_items, so it will iterate to the last element of the array. On Jul 4, 2005, at 3:33 PM, Shankar, Ganesh wrote: > > Hello All, > > I'm learning perl to process microarray data and mostly I've found it > very useful. However, I've come to a problem that I haven't been able > to solve. > > Background: One experiment generates two raw (tab-delimited)data > files. > The order of the lines in both these files are identical. I need to > grab 4 columns from each file and horizontally merge them in the > resulting results file. > > I've opened,read,split and pushed the elements into two arrays in > their > own foreach loops. > > push(our @red_elements, > ($red_items[6], "\t", $red_items[7], "\t", > $red_items[8], "\t", $red_items[9], "\n" > ) > ); > } #end foreach my $red_line > > push(our @green_elements, > ($green_items[6], "\t", $green_items[7], "\t", > green_items[8], "\t", $green_items[9], "\n" > ) > ); > } #end foreach my $red_line > > What I need in the final file is : > > ($red_items[6], "\t", $red_items[7], "\t", > $red_items[8], "\t", $red_items[9], "\t", > $green_items[6], "\t", $green_items[7], "\t", > green_items[8], "\t", $green_items[9], "\n" > > How do I iterate through two arrays at once? I've tried the > Array::Each > module, but I couldn't extend the example in the synopsis to multiple > columns. > > Thanks for any help. > > -Ganesh > > ========================================== Jim Brandt Administrative Computing Services University at Buffalo This email message may contain legally privileged and/or confidential information. If you are not the intended recipient(s), or the employee or agent responsible for the delivery of this message to the intended recipient(s), you are hereby notified that any disclosure, copying, distribution, or use of this email message is prohibited. If you have received this message in error, please notify the sender immediately by e-mail and delete this email message from your computer. Thank you. _______________________________________________ Buffalo-pm mailing list Buffalo-pm at pm.org http://mail.pm.org/mailman/listinfo/buffalo-pm This email message may contain legally privileged and/or confidential information. If you are not the intended recipient(s), or the employee or agent responsible for the delivery of this message to the intended recipient(s), you are hereby notified that any disclosure, copying, distribution, or use of this email message is prohibited. If you have received this message in error, please notify the sender immediately by e-mail and delete this email message from your computer. Thank you. From cbrandt at buffalo.edu Wed Jul 6 05:11:39 2005 From: cbrandt at buffalo.edu (Jim Brandt) Date: Wed, 6 Jul 2005 08:11:39 -0400 Subject: [Buffalo-pm] Question: How to iterate through 2 arrays andmerge columns In-Reply-To: <6FF91AE4F1DC7743A6466E334EB865AE02EB0240@VERITY.roswellpark.org> References: <6FF91AE4F1DC7743A6466E334EB865AE02EB0240@VERITY.roswellpark.org> Message-ID: I think my example mixed a few variable names as well, and that may have confused things. Looking at your original code, you are doing: > push(our @red_elements, > ($red_items[6], "\t", $red_items[7], "\t", > $red_items[8], "\t", $red_items[9], "\n" > ) > ); The parentheses (which I didn't see before) will create an anonymous array in each element of @red_elements. This can work for you since you've created a 2-dimensional array, which is really a table. So I think if you modify my code to do this: for (my $j=0;$j<=$#red_elements;$j++){ # Iterate through outer loop, one row at a time. for ( my $i=0; $i <= 7; $i++ ){ # You have eight columns, so this will go through each column and print it. print OUTFILE $red_elements[$j][$i]; } # Repeat for green_elements. for ( my $i=0; $i <= 7; $i++ ){ # You have eight columns, so this will go through each column and print it. print OUTFILE $green_elements[$j][$i]; } } # End outer loop. Note that you'll need to modify your code building the red_elements since you are currently putting a new line as the last element and I think you want a tab. That should work, but is a bit convoluted. I would simplify your earlier step to make it just a string rather than 8 elements in an array. For example: push(our @red_elements, $red_items[6] . "\t" . $red_items[7] . "\t" . $red_items[8] . "\t" . $red_items[9] . "\t" ); The dot is the string concatenation operator, so it will push all of that together into a single string. I think if you do it this way, my first example will work. Basically, it's playing with data structures two different ways. For what it's worth, I think Kevin's suggestion was the quickest and cleanest, but you don't get to play with data structures in perl. :) Good luck. Jim On Jul 5, 2005, at 10:33 PM, Shankar, Ganesh wrote: > Your suggestions were on the right track but maybe I wasn't clear > as to what I wanted. I need 4 cols from red followed by 4 cols > from green. The following code gives me 4 pairs of red(no space) > green(tab)(tab). > > I tried: > > for (my $j=0;$j<=$#red_items;$j++){ > push(@intermediate, $red_items[$j],$green_items[$j]); > } > print OUTFILE @intermediate; > > > What results is: > $red_items[6](no space)$green_items[6](2 tabs)$red_items[7](no > space)$green_items[7] > (2 tabs)$red_items[8](no space)$green_items[8](2tabs)$red_items[9] > (nospace)$green_items[9] ========================================== Jim Brandt Administrative Computing Services University at Buffalo From Ganesh.Shankar at RoswellPark.org Thu Jul 7 01:37:42 2005 From: Ganesh.Shankar at RoswellPark.org (Shankar, Ganesh) Date: Thu, 7 Jul 2005 04:37:42 -0400 Subject: [Buffalo-pm] Question: How to iterate through 2 arrays and merge columns Message-ID: <6FF91AE4F1DC7743A6466E334EB865AE02EB0242@VERITY.roswellpark.org> Hello All, Again,thanks for taking the time to walk me through this. As you suggested, I started working with the data as strings. This made it conceptually easier to deal with and I wanted to avoid thinking about anonymous arrays at this point. The approach at this point looks like this:- open( REDOPEN, $red_file ) or die $!; print "opened " . $red_file . "\n"; my $i; for ( $i = 0 ; $i < 21 ; $i++ ) { print "looping through header line $i \n"; ; } my @red = ; foreach my $red_line (@red) { our @red_items = split( '\t', $red_line ); push(our @red_elements, $red_items[6]. "\t", $red_items[7]."\t", $red_items[8]. "\t", $red_items[9]. "\t" ); } #end foreach my $red_line ...There is a similar block for dealing with green data... Here is the loop to concatanate the two strings together. for (my $i= 0;$i <= $#red_elements; $i++){ print OUTFILE $red_elements[$i],$green_elements[$i]; } When I execute this, I get the following error:- Variable "@red_elements" is not imported at line 80 (#1) (F) While "use strict" in effect, you referred to a global variable that you apparently thought was imported from another module, because something else of the same name (usually a subroutine) is exported by that module. It usually means you put the wrong funny character on the front of your variable. Line 80 corresponds to this line: for (my $i= 0;$i <= $#red_elements; $i++){ I thought declaring @red_elements to be 'our' made it available throughout the program? Is scoping the problem? I thought I'd cheat, and turned off 'use strict'. At that point, I got an uninitialized variable error pointing to this line: push(our @red_elements, Looks like the two errors are related and solving the first error should take care of the uninitialized variable error. Any pointers? Where can I read about this? Thanks again. -Ganesh Shankar -----Original Message----- From: Jim Brandt [mailto:cbrandt at buffalo.edu] Sent: Wed 7/6/2005 8:11 AM To: Shankar, Ganesh Cc: buffalo-pm at pm.org Subject: Re: [Buffalo-pm] Question: How to iterate through 2 arrays andmerge columns I think my example mixed a few variable names as well, and that may have confused things. Looking at your original code, you are doing: > push(our @red_elements, > ($red_items[6], "\t", $red_items[7], "\t", > $red_items[8], "\t", $red_items[9], "\n" > ) > ); The parentheses (which I didn't see before) will create an anonymous array in each element of @red_elements. This can work for you since you've created a 2-dimensional array, which is really a table. So I think if you modify my code to do this: for (my $j=0;$j<=$#red_elements;$j++){ # Iterate through outer loop, one row at a time. for ( my $i=0; $i <= 7; $i++ ){ # You have eight columns, so this will go through each column and print it. print OUTFILE $red_elements[$j][$i]; } # Repeat for green_elements. for ( my $i=0; $i <= 7; $i++ ){ # You have eight columns, so this will go through each column and print it. print OUTFILE $green_elements[$j][$i]; } } # End outer loop. Note that you'll need to modify your code building the red_elements since you are currently putting a new line as the last element and I think you want a tab. That should work, but is a bit convoluted. I would simplify your earlier step to make it just a string rather than 8 elements in an array. For example: push(our @red_elements, $red_items[6] . "\t" . $red_items[7] . "\t" . $red_items[8] . "\t" . $red_items[9] . "\t" ); The dot is the string concatenation operator, so it will push all of that together into a single string. I think if you do it this way, my first example will work. Basically, it's playing with data structures two different ways. For what it's worth, I think Kevin's suggestion was the quickest and cleanest, but you don't get to play with data structures in perl. :) Good luck. Jim On Jul 5, 2005, at 10:33 PM, Shankar, Ganesh wrote: > Your suggestions were on the right track but maybe I wasn't clear > as to what I wanted. I need 4 cols from red followed by 4 cols > from green. The following code gives me 4 pairs of red(no space) > green(tab)(tab). > > I tried: > > for (my $j=0;$j<=$#red_items;$j++){ > push(@intermediate, $red_items[$j],$green_items[$j]); > } > print OUTFILE @intermediate; > > > What results is: > $red_items[6](no space)$green_items[6](2 tabs)$red_items[7](no > space)$green_items[7] > (2 tabs)$red_items[8](no space)$green_items[8](2tabs)$red_items[9] > (nospace)$green_items[9] ========================================== Jim Brandt Administrative Computing Services University at Buffalo This email message may contain legally privileged and/or confidential information. If you are not the intended recipient(s), or the employee or agent responsible for the delivery of this message to the intended recipient(s), you are hereby notified that any disclosure, copying, distribution, or use of this email message is prohibited. If you have received this message in error, please notify the sender immediately by e-mail and delete this email message from your computer. Thank you. From Ganesh.Shankar at RoswellPark.org Thu Jul 7 02:48:59 2005 From: Ganesh.Shankar at RoswellPark.org (Shankar, Ganesh) Date: Thu, 7 Jul 2005 05:48:59 -0400 Subject: [Buffalo-pm] Question: How to iterate through 2 arrays and merge columns Message-ID: <6FF91AE4F1DC7743A6466E334EB865AE02EB0245@VERITY.roswellpark.org> Ok, after my previous post, I was able to resolve the '@red_elements is not imported' error by placing the 'our @red_elements;' at the top of the program. The 'uninitialized value' warning is still present, but the script runs. Code snippet is at the end of the message. However, the format of the output is: red1 tab green1 tab red2 tab green2 tab etc. What I need is : red1 tab red2 tab red3 tab red4 tab green1 tab green2 tab green3 tab green4. I thought that since the strings were in the correct order, print OUTFILE $red_elements[$i],$green_elements[$i]; would just concatanate the two strings. Not! I tried print OUTFILE $red_elements[$i]."\t".$green_elements[$i]; but that results in the same pattern, but with an extra tab in between elements. Thanks for any help. -Ganesh open( REDOPEN, $red_file ) or die $!; print "opened " . $red_file . "\n"; my $i; for ( $i = 0 ; $i < 21 ; $i++ ) { print "looping through header line $i \n"; ; } my @red = ; foreach my $red_line (@red) { our @red_items = split( '\t', $red_line ); push( @red_elements, $red_items[6]. "\t", $red_items[7]."\t", $red_items[8]. "\t", $red_items[9]. "\t" ); } #end foreach my $red_line for (my $i= 0;$i <= $#red_elements; $i++){ print OUTFILE $red_elements[$i]."\t".$green_elements[$i]; } -----Original Message----- From: Jim Brandt [mailto:cbrandt at buffalo.edu] Sent: Wed 7/6/2005 8:11 AM To: Shankar, Ganesh Cc: buffalo-pm at pm.org Subject: Re: [Buffalo-pm] Question: How to iterate through 2 arrays andmerge columns I think my example mixed a few variable names as well, and that may have confused things. Looking at your original code, you are doing: > push(our @red_elements, > ($red_items[6], "\t", $red_items[7], "\t", > $red_items[8], "\t", $red_items[9], "\n" > ) > ); The parentheses (which I didn't see before) will create an anonymous array in each element of @red_elements. This can work for you since you've created a 2-dimensional array, which is really a table. So I think if you modify my code to do this: for (my $j=0;$j<=$#red_elements;$j++){ # Iterate through outer loop, one row at a time. for ( my $i=0; $i <= 7; $i++ ){ # You have eight columns, so this will go through each column and print it. print OUTFILE $red_elements[$j][$i]; } # Repeat for green_elements. for ( my $i=0; $i <= 7; $i++ ){ # You have eight columns, so this will go through each column and print it. print OUTFILE $green_elements[$j][$i]; } } # End outer loop. Note that you'll need to modify your code building the red_elements since you are currently putting a new line as the last element and I think you want a tab. That should work, but is a bit convoluted. I would simplify your earlier step to make it just a string rather than 8 elements in an array. For example: push(our @red_elements, $red_items[6] . "\t" . $red_items[7] . "\t" . $red_items[8] . "\t" . $red_items[9] . "\t" ); The dot is the string concatenation operator, so it will push all of that together into a single string. I think if you do it this way, my first example will work. Basically, it's playing with data structures two different ways. For what it's worth, I think Kevin's suggestion was the quickest and cleanest, but you don't get to play with data structures in perl. :) Good luck. Jim On Jul 5, 2005, at 10:33 PM, Shankar, Ganesh wrote: > Your suggestions were on the right track but maybe I wasn't clear > as to what I wanted. I need 4 cols from red followed by 4 cols > from green. The following code gives me 4 pairs of red(no space) > green(tab)(tab). > > I tried: > > for (my $j=0;$j<=$#red_items;$j++){ > push(@intermediate, $red_items[$j],$green_items[$j]); > } > print OUTFILE @intermediate; > > > What results is: > $red_items[6](no space)$green_items[6](2 tabs)$red_items[7](no > space)$green_items[7] > (2 tabs)$red_items[8](no space)$green_items[8](2tabs)$red_items[9] > (nospace)$green_items[9] ========================================== Jim Brandt Administrative Computing Services University at Buffalo This email message may contain legally privileged and/or confidential information. If you are not the intended recipient(s), or the employee or agent responsible for the delivery of this message to the intended recipient(s), you are hereby notified that any disclosure, copying, distribution, or use of this email message is prohibited. If you have received this message in error, please notify the sender immediately by e-mail and delete this email message from your computer. Thank you. From cbrandt at buffalo.edu Thu Jul 7 04:49:49 2005 From: cbrandt at buffalo.edu (Jim Brandt) Date: Thu, 7 Jul 2005 07:49:49 -0400 Subject: [Buffalo-pm] Question: How to iterate through 2 arrays and merge columns In-Reply-To: <6FF91AE4F1DC7743A6466E334EB865AE02EB0245@VERITY.roswellpark.org> References: <6FF91AE4F1DC7743A6466E334EB865AE02EB0245@VERITY.roswellpark.org> Message-ID: You still have commas in here, so it's not creating one big string. You need to convert all of the commas to periods, including the ones after the "\t". If you fix that, I think you should be all set. As far as your 'our' problems, here's the snippet from the docs: An "our" declares the listed variables to be valid globals within the enclosing block, file, or "eval". That is, it has the same scoping rules as a "my" declaration, but does not cre- ate a local variable. The trick is "within the enclosing block," which in your case was the 'for' loop. In general, most normal programs never need 'our'. You should just just 'my', and watch out for the scoping issue you ran into. On Jul 7, 2005, at 5:48 AM, Shankar, Ganesh wrote: > push( @red_elements, > $red_items[6]. "\t", $red_items[7]."\t", > $red_items[8]. "\t", $red_items[9]. "\t" > ); ========================================== Jim Brandt Administrative Computing Services University at Buffalo From Ganesh.Shankar at RoswellPark.org Fri Jul 8 05:59:06 2005 From: Ganesh.Shankar at RoswellPark.org (Shankar, Ganesh) Date: Fri, 8 Jul 2005 08:59:06 -0400 Subject: [Buffalo-pm] Question: How to iterate through 2 arrays and merge columns Message-ID: <6FF91AE4F1DC7743A6466E334EB865AE0BF84BFB@VERITY.roswellpark.org> That was it! Thanks. I'm still getting the uninitialized value warning, but the script works. I'm moving on, but I'll keep trying to figure out the warning. Thanks, again. -Ganesh -----Original Message----- From: Jim Brandt [mailto:cbrandt at buffalo.edu] Sent: Thursday, July 07, 2005 7:50 AM To: Shankar, Ganesh Cc: buffalo-pm at pm.org Subject: Re: [Buffalo-pm] Question: How to iterate through 2 arrays and merge columns You still have commas in here, so it's not creating one big string. You need to convert all of the commas to periods, including the ones after the "\t". If you fix that, I think you should be all set. As far as your 'our' problems, here's the snippet from the docs: An "our" declares the listed variables to be valid globals within the enclosing block, file, or "eval". That is, it has the same scoping rules as a "my" declaration, but does not cre- ate a local variable. The trick is "within the enclosing block," which in your case was the 'for' loop. In general, most normal programs never need 'our'. You should just just 'my', and watch out for the scoping issue you ran into. On Jul 7, 2005, at 5:48 AM, Shankar, Ganesh wrote: > push( @red_elements, > $red_items[6]. "\t", $red_items[7]."\t", > $red_items[8]. "\t", $red_items[9]. "\t" > ); ========================================== Jim Brandt Administrative Computing Services University at Buffalo This email message may contain legally privileged and/or confidential information. If you are not the intended recipient(s), or the employee or agent responsible for the delivery of this message to the intended recipient(s), you are hereby notified that any disclosure, copying, distribution, or use of this email message is prohibited. If you have received this message in error, please notify the sender immediately by e-mail and delete this email message from your computer. Thank you. From sgriffit at gennum.com Fri Jul 8 06:51:49 2005 From: sgriffit at gennum.com (Shaun Griffith) Date: Fri, 8 Jul 2005 09:51:49 -0400 Subject: [Buffalo-pm] Question: How to iterate through 2 arrays andmerge columns In-Reply-To: <6FF91AE4F1DC7743A6466E334EB865AE0BF84BFB@VERITY.roswellpark.org> Message-ID: <00e801c583c4$308f6620$c417005a@headoffice.gennum.com> Shankar, Ganesh wrote: > That was it! Thanks. I'm still getting the uninitialized > value warning, > but the script works. I'm moving on, but I'll keep trying to > figure out > the warning. I'd suspect that your input is missing fields, or the files aren't the same length, or somesuch. Use the debugger or add if () { print...} statements to indicate where in the input file(s) the problem occurs (line numbers would be helful). -------------- next part -------------- A non-text attachment was scrubbed... Name: winmail.dat Type: application/ms-tnef Size: 1788 bytes Desc: not available Url : http://mail.pm.org/pipermail/buffalo-pm/attachments/20050708/359ac80c/winmail.bin From Ganesh.Shankar at RoswellPark.org Mon Jul 11 08:29:43 2005 From: Ganesh.Shankar at RoswellPark.org (Shankar, Ganesh) Date: Mon, 11 Jul 2005 11:29:43 -0400 Subject: [Buffalo-pm] Question: How to iterate through 2 arrays and merge columns Message-ID: <6FF91AE4F1DC7743A6466E334EB865AE0BF84BFE@VERITY.roswellpark.org> Thanks. I'll confirm that the input files are in the expected format. And probably put in checks to ensure proper behavior if they are not. Thanks again. -Ganesh -----Original Message----- From: Shaun Griffith [mailto:sgriffit at gennum.com] Sent: Friday, July 08, 2005 9:52 AM To: Shankar, Ganesh Cc: buffalo-pm at pm.org Subject: RE: [Buffalo-pm] Question: How to iterate through 2 arrays andmerge columns Shankar, Ganesh wrote: > That was it! Thanks. I'm still getting the uninitialized > value warning, > but the script works. I'm moving on, but I'll keep trying to > figure out > the warning. I'd suspect that your input is missing fields, or the files aren't the same length, or somesuch. Use the debugger or add if () { print...} statements to indicate where in the input file(s) the problem occurs (line numbers would be helful). This email message may contain legally privileged and/or confidential information. If you are not the intended recipient(s), or the employee or agent responsible for the delivery of this message to the intended recipient(s), you are hereby notified that any disclosure, copying, distribution, or use of this email message is prohibited. If you have received this message in error, please notify the sender immediately by e-mail and delete this email message from your computer. Thank you.