Hello, How do you print the return value from a subroutine to a file?
Particularly, when you are using pass by value.
#!/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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.