#!/usr/local/bin/perl
#===============================================================================
#
#         FILE:  example.pl
#
#        USAGE:  ./example.pl 
#
#  DESCRIPTION:  Example for Perl Seminar
#                * Read a list of star designations and altitudes
#                * Print only stars with HD number that are "above horizon"
#
#        NOTES:  ---
#       AUTHOR:  Ulrike Heiter (UH), <ulrikeATastro.uu.se>
#      CREATED:  2005-12-14 11.06.50 MET
#     REVISION:  2005-12-14 11.06.50 MET
#         TODO:  ---
#===============================================================================

# Inititalize

@starlist = ();
%altitude = ();

# Read file

read_file();

# Print selected stars

foreach $star (@starlist) {
   if (select_star($star,$altitude{$star})) {
      print $star;
   }
} # -----  end foreach  -----

# Subroutines

sub read_file {
   open FILE, "< starfile";
   while (<FILE>) {
      push @starlist, $_;
      $altitude{$_} = <FILE>;
   }
   close FILE;
} # ----------  end of subroutine read_file ----------

sub select_star {
   my ($name, $altitude) = @_;
   if ( ($name =~ /^HD/) and ($altitude > 10) ) {
      return 1; # anything else but "0" or "" is TRUE
   }
   else {
      return 0; # "0" is FALSE
   }
} # ----------  end of subroutine select_star  ----------

