#!/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); }
In reply to printing sub return values to a file by lomSpace
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |