title: In Perl, how can I read the contents of a file into an array?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/761392/easiest-way-to-open-a-text-file-and-read-it-into-an-array-with-perl">Easiest way to open a text file and read it into an array with Perl</a>  </p>
  </blockquote>
  
  
  
  <p>I'm new to Perl and want for each file push the contents of that file in one separate array, I managed to do so by the following, which uses if statements. But, I want something like $1 for my arrays. Is that possible? </p>
  
  <pre><code>#!/usr/bin/perl
  
  use strict;
  my @karray;
  my @sarray;
  my @testarr = (@sarray,@karray);
  my $stemplate = "foo.txt";
  my $ktemplate = "bar.txt";
  sub pushf2a  {
    open(IN, "&lt;$_[0]") || die;
    while (&lt;IN&gt;) {
      if ($_[0] eq $stemplate) {
        push (@sarray,$_);
      } else {
        push (@karray,$_);
      } 
    }
    close(IN) || die  $!;
  }
  &amp;pushf2a($stemplate,@sarray);
  &amp;pushf2a($ktemplate,@karray);
  print sort @sarray;
  print sort @karray;
  </code></pre>
  
  <p>I want something like this:</p>
  
  <pre><code>#!/bin/sh
  myfoo=(@s,@k)
  barf() {
    pushtoarray $1
  }
  barf @s
  barf @k
  </code></pre>