2

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";
    [...]}
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Pedro
  • 41
  • 6

1 Answers1

1

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>);
TLP
  • 66,756
  • 10
  • 92
  • 149
  • Oh sorry, the global variable was something I wanted to delete it came from another try ... but I made the globals local now (see edited code above) and it still does not work. – Pedro Aug 08 '21 at 18:00
  • Then you can try the advice I gave 2 hours ago and chomp your STDIN input. Maybe that will help. – TLP Aug 08 '21 at 18:04
  • I'll change my answer. – TLP Aug 08 '21 at 18:15