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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:31:05+00:00 2026-06-11T11:31:05+00:00

I have trouble in assigning an argument value / command line arguments. Here is

  • 0

I have trouble in assigning an argument value / command line arguments. Here is what i actually want to do.

Test.pl
#!/usr/bin/perl

#Variable declaration

$RUN_DIR="/home/ckhau/database/experiment/test";
    #Main program

$index=-999; 
#my $ARGV;
@files = <$RUN_DIR/b*.txt>;

foreach $file (@files)
{
 #$SCRIPT="perl abcdinfo.pl $file";
 $SCRIPT="perl abc.pl $file";
 system("$SCRIPT");       
}

I tried replacing b*.txt with @ARGV and tried running the program i.e when i replace the above code with

@files = <$RUN_DIR/@ARGV>;

Then try to run with command line

perl Test.pl b*.txt

This gives me an error perl: no match. Can anyone help me on the following.

How to use command line argument for this ???

Can i use these kind of syntax in command lines “b*.txt” or “r_*.txt”???

  • 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-11T11:31:06+00:00Added an answer on June 11, 2026 at 11:31 am

    The shell is trying to expand b*.txt to the list of matching files in your current directory. Once your program receives those values, your glob looks like

    @files = </home/ckhau/database/experiment/test/b1.txt b3.txt b3.txt>
    

    which isn;t what you want, and will fail to find any files if there is no b1.txt in your $RUN_DIR directory

    To prevent the shell globbing a wildcard file pattern you just need to put it in quotes, so your command becomes

    perl Test.pl 'b*.txt'
    

    Beyond that, your program really needs improving. You should always use strict and use warnings at the head of all your programs, and declare every variable at its point of first use; you should really use just the first element of @ARGV as your file pattern, instead of the whole array; and it is wrong to put scalar variables in quotes when you simply want their contents

    Take a look at this refactoring of your original

    #!/usr/bin/perl
    
    use strict;
    use warnings;
    
    my $run_dir="/home/ckhau/database/experiment/test";
    
    my $pattern = "$run_dir/$ARGV[0]";
    
    my $index = -999; 
    my @files = glob $pattern;
    
    foreach my $file (@files) {
      my $script = "perl abc.pl '$file'";
      system $script;
    }
    

    Update

    If you really want to have multiple wildcard patterns as parameters to Test.pl then you must patch the $run_dir directory onto the beginning of each of them. The best way to do this is to employ the File::Spec module’s rel2abs function. The complete script would look like this

    #!/usr/bin/perl
    
    use strict;
    use warnings;
    
    use File::Spec;
    
    my $run_dir="/home/ckhau/database/experiment/test";
    
    my $pattern = join ' ', map File::Spec->rel2abs($_, $run_dir), @ARGV;
    
    my $index = -999;
    my @files = glob $pattern;
    
    foreach my $file (@files) {
      my $script = "perl abc.pl '$file'";
      system $script;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have trouble doing this... You may want to get the same result as
I have trouble getting a form element value into a jstl tag. I am
I am having trouble assigning the value of an NSString to a char *
I have trouble finding the right way to add cells into columns: Here is
Fairly new to .Net here and having trouble with a line of code. I
I'm using rails 3.2.3 and am having trouble assigning a value in my HABTM
I have trouble figuring out why a simple division like this one always returns
We have trouble implementing a nice session mechanism in JSP. One of our requirement
I have trouble with strange behavior of for..in cycle in JavaScript. I have the
I have trouble shooting at file download problem. In Chrome, the download works fine.

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.