#!/usr/bin/perl -w

use warnings;
use strict;
use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
use Pod::Usage qw( pod2usage );
use IPC::Cmd 0.36 qw( can_run run );

my $path = undef;
my $list = undef;

GetOptions(
        'path|p=s' => \$path,
        'list|l=s' => \$list,
        ) or pod2usage( 2 );


pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
pod2usage(
        -msg => "\n   Required options:\n\n".
        "--path <pathToJobsDir>\n".
        "--list <listOfJobNames>\n\n",
        -exitval => 3
        ) unless
defined $path and
defined $list;

my $job;
open (LIST, "$list") || die "couldn't open the file at '$list'";

while ($job = <LIST>) {

    chomp($job);

    my @cmdOut = `tar -ztf $path/$job/B000.tar.gz`;

    my $line;
    foreach $line (@cmdOut) {

        if ($line =~ m/.*B000\/(\d+)\.FITS/) {

            print "$1\n";

        }

    }

}

close(LIST);



