Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6250727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:28:49+00:00 2026-05-24T13:28:49+00:00

I am trying to convert the use of @ARGV with using Getopt::Std instead in

  • 0

I am trying to convert the use of @ARGV with using Getopt::Std instead in my perl script.
I am getting some substr errors and need some help figuring this out.

Errors:

Use of uninitialized value in substr at ./h.pl line 33.
Use of uninitialized value in substr at ./h.pl line 33.
substr outside of string at ./h.pl line 33.
Use of uninitialized value in substr at ./h.pl line 33.
substr outside of string at ./h.pl line 33.
The 'month' parameter (undef) to DateTime::new was an 'undef', which is not one of the allowed types: scalar
 at /usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi/DateTime.pm line 176
    DateTime::new('undef', 'HASH(0xb6932d0)') called at ./h.pl line 33

Here is my code. (commented out code was working code using @ARGV)

use strict;
use warnings;
use Getopt::Std;
use DateTime;

# Getopt usage
my %opt;
getopts ('fd:ld:h', \%opt);

$opt{h} and &Usage;
my $first_date     = $opt{fd};
my $last_date      = $opt{ld};

#unless(@ARGV==2)
#{
#    print "Usage: myperlscript first_date last_date\n";
#    exit(1);
#}
#
#my ($first_date,$last_date)=@ARGV;

# Convert using Getopts
my $date=DateTime->new(
{
  year=>substr($first_date,0,4),
  month=>substr($first_date,4,2),
  day=>substr($first_date,6,2)
});

while($date->ymd('') le $last_date)
{
  print $date->ymd('') . "\n";
  $date->add(days=>1);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T13:28:50+00:00Added an answer on May 24, 2026 at 1:28 pm

    “getopt, getopts – Process single-character switches with switch clustering”

    As only single character switches are allowed $opt{fd} and $opt{ld} are undef.

    Getopt::Long does what you want.

    use strict;
    use warnings;
    use Getopt::Long;
    
    my $fd;
    my $ld;
    
    my $result = GetOptions(
        'fd=s' => \$fd,
        'ld=s' => \$ld,
    );
    
    die unless $result;
    
    print "fd: $fd\n";
    print "ld: $ld\n";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to convert my spark views to use ViewData.Model instead of the
I've inherited some code... and am trying to convert it to use MVC 3,
I am getting following error when I am trying to use Convert.FromBase64String The input
I trying to convert some loops in my code to use the for_each functionality
I'm trying to convert the following ereg() call to use preg_match() instead: if (ereg('(.*/)(.*)$',$fileref,$reg)
I'm trying to convert my existing site to use WCF to communicate with my
I'm trying to convert a current Django project in development to use zc.buildout So
I'm trying to convert an ASP.NET web application to use resource files. I haven't
I'm trying to convert a piece of Objective-C code into C# for use with
I'm trying to use strtotime to convert the following date: 07/09/2009 17:01:27 It's the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.