Harvesting repository // "From=>" and "Until=>" with user input variable

69 Views Asked by At

I am using „from=>“ and “until=>” while harvesting a repository with OAI-PMH written in Perl. I tried to let the user type in start- and end-date with <STDIN> in format yyyy-mm-dd. But instead of giving me back the records/results the compiler seems to ignore my query / request, at least it does not give me any results. I have enclosed the relevant parts of the code below. Thanks for your help!

#! /usr/bin/perl

use warnings;
use strict;

use Net::OAI::Harvester;
use Time::Piece;
use Time::Seconds;

my $harvester = Net::OAI::Harvester->new( 
    baseURL => 'https://opus4.XXX/oai'
);

my $weekAgo = localtime() - ONE_WEEK;
$weekAgo = $weekAgo->ymd;

my $monthAgo = localtime() - ONE_MONTH;
$monthAgo = $monthAgo->ymd;

print "Please enter a number \n
        1 for last weeks records \n
        2 for last months records \n
        3 for records from ... until ...\n";
my $input = <STDIN>;

[...]
elsif( $input == 3 ) {
        print "enter start date (yyyy-mm-dd): ";
        my $from = <STDIN>;
        print "Enter final date (yyyy-mm-dd): ";
        my $until = <STDIN>;

        my $list = $harvester->listRecords(
            metadataPrefix  => 'oai_dc',
            from=>$from,
            until=>$until
        );

        search($list);
}

sub search {
    my $list = $_[0];
while ( my $record = $list->next ) { 
    my $datestamp = $record->header->datestamp;
    print "[ time stamp: ",$datestamp," ]","\n";
    my $metadata = $record->metadata;
    print "Title: ",$metadata->title,"\n";
    [...]}
}
1

There are 1 best solutions below

3
On

Changed answer due to feedback

Try chomping your input. It may confuse the module you are passing the values to. E.g. change

    my $from = <STDIN>;

to

    chomp(my $from = <STDIN>);