Help for this page

Select Code to Download


  1. or download this
    while (<FH>) {
       chomp $_;
       $a[$i]=$_;
       $i++;
    }
    
  2. or download this
    @a = <FH>;  # diamond operator in "list" (or array) context
                # will read all input records into array elements
    chomp @a;   # chomp can work on a list
    
  3. or download this
    while (<FH>) {
       chomp;        # $_ is the default arg to chomp;
    ...
    
       push @a, $_;  # add a new element at end of @a
    }
    
  4. or download this
     perl -e '@a=qw/one two three four/; print @a,$/'
    
     perl -e '@a=qw/one two three four/; print "@a$/"'
    
     perl -e '@a=qw/one two three four/; print join(" ", map { "foo=$_" } 
    +@a), $/'