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

  • SEARCH
  • Home
  • 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 7853739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:47:13+00:00 2026-06-02T19:47:13+00:00

I am a beginner PERL programmer and I have come across a snag that

  • 0

I am a beginner PERL programmer and I have come across a snag that I can’t get by. I have been reading and re-reading web posts and Simon Cozens book at perl.org all day, but can’t seem to solve the problem.

My intention with the code below is to loop through files in a directory and when the file has a certain string a name to verify that the same file name doesn’t exist with a different extension and if it doesn’t, to print me the file name (later I will implement a delete of the file, but for now I want to ensure it will work.) Specifically, I am finding .mdb files and after checking there are no associated .ldb’s files, deleting the .mdb file.

right now my code returns this:

RRED_Database_KHOVIS.ldb
RRED_Database_KHOVIS.mdb
I will kill RRED_Database_KHOVIS.mdb

RRED_Database_mkuttler.mdb
I will kill RRED_Database_mkuttler.mdb

RRED_Database_SBreslow.ldb
RRED_Database_SBreslow.mdb
I will kill RRED_Database_SBreslow.mdb

i want it to only return the “I will kill…” after a .mdb file with no associated .ldb file.

My current code is below. I appreciate any help offered…

use strict;
use warnings;
use File::Find;
use diagnostics;

my $dir = "//vfg1msfs01ab/vfgcfs01\$/Regulatory Reporting/Access Database/";
my $filename = "RRED_Database";
my $fullname, my $ext;

opendir DH, $dir or die "Couldn't open the directory: $!";
while ($_ = readdir(DH)) {
my $ext = ".mdb";
if ((/$filename/) && ($_ ne $filename . $ext)) {
    print "$_ \n";
    unless (-e $dir . s/.mdb/.ldb/) {
        s/.ldb/.mdb/;
        print "I will kill $_ \n\n" ;
        #unlink $_ or print "oops, couldn't delete $_: $!\n";
    }
    s/.ldb/.mdb/;
}   
}
  • 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-06-02T19:47:15+00:00Added an answer on June 2, 2026 at 7:47 pm

    When looping through files, I like to use ‘next’ statements repeatedly to assure that I’m only looking at exactly what I want. Try this:

    use strict;
    use warnings;
    use File::Find;
    use diagnostics;
    
    my $dir = "//vfg1msfs01ab/vfgcfs01\$/Regulatory Reporting/Access Database/";
    my $filename = "RRED_Database";
    my $fullname, my $ext;
    
    opendir DH, $dir or die "Couldn't open the directory: $!";
    while ($_ = readdir(DH)) {
      my $ext = ".mdb";
    
      # Jump to next while() iteration unless the file begins 
      # with $filename and ends with $ext, 
      # and capture the basename in $1
      next unless $_ =~ m|($filename.*)$ext|;
    
      # Jump to next while() iteration if if the file basename.ldb is found
      next if -f $1 . ".ldb";
    
      # At this point, we have an mdb file with no matching ldb file
      print "$_ \n";
      print "I will kill $_ \n\n" ;
      #unlink $_ or print "oops, couldn't delete $_: $!\n";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Beginner programmer here....hope it makes sense :) I have created a console app that
Beginner level question Scenario: Have simple string cocantation tool, that I might expand later
Absolute beginner question: I have a template file index.html that looks like this: ...
Rails beginner here.. I have a users resource where I implemented a callback that's
I am a beginner to Perl syntax and have a basic wildcard question. I
I am kinda beginner in perl and I need know how can I check
Beginner programmer here. So bear with me. I have a simple python program. print
I'm a beginner in Perl. I have a Windows batch script which contains multiple
So I have this assignment for a beginner course in Perl and I have
Beginner rails/javascript question: Let's say that I have a simple Circle model in a

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.