lomSpace has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; use FileHandle; use Data::Dumper; open(my $in1, "/Users/mydir/Desktop/hw3_infile1.txt"); open(my $report, ">/Users/mydir/Desktop/hw3_report.txt"); my @aa_seqs = ("MPIGSKERPTFFEIFKTRCNKADLGPIS", "MDLSALRVEEVQNVINAMQKIL +ECPIC", "MDLSAVQIQEVQNVLHAMQKILECPICLE"); my @nt_seqs = ("atgccgctaccgt", "cgcctagcgccgcatta","ccgtaggcattc", "g +acctaggtcag"); #call subroutines #pass by value $report print $report "Values returned via pass by value:\n"; my @oligo_array = get_oligo_seqs($in1); # pass by value print "@oligo_array\n"; close($in1); #print results print $report "Before calling subroutine:\n"; for my $aa_seqs(@aa_seqs){ print $report "$aa_seqs\n"; } print $report "\n"; for my $nt_seqs(@nt_seqs){ print $report "$nt_seqs\n"; } print $report "\n"; #pass by reference change_array(\@aa_seqs, \@nt_seqs); #print results print $report "After calling subroutine:\n"; for my $aa_seqs(@aa_seqs){ print $report "$aa_seqs\n"; } print $report "\n"; for my $nt_seqs(@nt_seqs){ print $report "$nt_seqs\n"; } close($report); ######## Subroutines ######### sub get_oligo_seqs{ my ($fh) = shift; while(<$fh>){ my @fields = split /\t/; my $oligos = $fields[1]; print "$oligos\n"; } } sub change_array{ my ($aa, $nt) = @_; push(@$nt, 'ggacttacgggccatataa'); shift(@$aa); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: printing sub return values to a file
by ikegami (Patriarch) on Nov 19, 2009 at 07:03 UTC | |
|
Re: printing sub return values to a file
by cdarke (Prior) on Nov 19, 2009 at 08:41 UTC | |
by JadeNB (Chaplain) on Nov 19, 2009 at 16:15 UTC | |
by lomSpace (Scribe) on Nov 19, 2009 at 20:48 UTC | |
by toolic (Bishop) on Nov 19, 2009 at 21:03 UTC | |
by ikegami (Patriarch) on Nov 19, 2009 at 21:29 UTC | |
by lomSpace (Scribe) on Nov 19, 2009 at 21:23 UTC |