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 3500696
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:45:58+00:00 2026-05-18T12:45:58+00:00

Sorry, if this to verbose, but I have a perl script that is partly

  • 0

Sorry, if this to verbose, but I have a perl script that is partly working. I have a regular expression that extracts either foo|bar and a prefix on a string given. But the problem is my strings are also FILE NAMES which I also want to open and retrieve its contents like locale_col.dat.2010120813.png (see Expected Output below).

The output now looks like this:

Content:/home/myhome/col/.my_file_del.mail@locale.foo.org
Key1:foo:Key2:col
Content:/home/myhome/col/.my_file_del.dp1.bar.net
Key1:bar:Key2:col
Content:/home/myhome/jab/.my_file_del.mail@locale.foo.org
Key1:foo:Key2:jab
Content:/home/myhome/jab/.my_file_del.dp1.bar.net
Key1:bar:Key2:jab

I need help tweaking this so that in one pass I can read the list of strings (file names from FileList.txt), extract particular values from the file name path (using regex) and open the file name for its contents. I hope that makes sense or am I looking at breaking this into 2 perl scripts? Thanks for your input.

Code (WIP):

open FILE, "< /home/myname/FileList.txt";
while (<FILE>) {
 my $line = $_;
   chomp($line);
      print "Content:$_"; #This is just printing the filenames. 
                #I want to get the contents of those file names instead. Stuck here.
      if ($line =~ m/home\/myname\/(\w{3}).*[.](\w+)[.].*/){
         print "Key1:$2:Key2:$1\n";
      }
}
close FILE;

Contents of FileList.txt:

/home/myname/col/.my_file_del.mail@locale.foo.org
/home/myname/col/.my_file_del.dp1.bar.net
/home/myname/jab/.my_file_del.mail@locale.foo.org
/home/myname/jab/.my_file_del.dp1.bar.net

Example content of one of the listed files: (which I need help here with to extract)

$ cat .my_file_del.mail@locale.foo.org 
locale_col.dat.2010120813.png

Expected Output:

Content:locale_col.dat.2010120813.png
Key1:foo:Key2:col
...
..
  • 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-18T12:45:59+00:00Added an answer on May 18, 2026 at 12:45 pm

    Here is a way to do it:

    #!/usr/bin/perl
    # ALWAYS these 2 lines !!!
    use strict;
    use warnings;
    
    my $file = '/home/myname/FileList.txt';
    # use 3 args open and test openning for failure
    open my $FILE, '<', $file or die "unable to open '$file' for reading: $!";
    while (my $line = <$FILE>) {
        chomp($line);
        print "Content:$line\n"; #This is just printing the filenames. 
        #I want to get the contents of those file names instead. Stuck here.
        if ($line =~ m#home/myname/(\w{3}).*[.](\w+)[.].*#) {
            open my $file2, '<', $line or die "unable to open '$file' for reading: $!";
            while(my line2 = <$file2>) {
              print $line2;
            }
            close $file2;
            print "Key1:$2:Key2:$1\n";
        }
    }
    close $FILE;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry if this is a little off-topic for regular stackoverflow questions, but we're tearing
Sorry this is basic, but I'm new to Python and Django. I have a
Ok sorry this might seem like a dumb question but I cannot figure this
Sorry for this not being a real question, but Sometime back i remember seeing
Sorry if this sounds like a really stupid question, but I need to make
Sorry, if this is a noobish question, but I'm just getting started with Rails
Sorry for the confusing title. I tried to make it less verbose, but... What
Sorry this is probably stupid wood for trees stuff but: All I want is
First, sorry this is so long. I probably don't need all the code, but
sorry this is probably an embarassing noob question for c#, but I came across

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.