-1

I need to input a variable into this line to process many files dynamically:

open (INFILE, "< your_input.fa") 

I don't know how to accomplish this using Perl. I would normally use bash commands in a similar manner:

NAME1=$PWD
NAME=$(basename "$NAME1") 

bwa mem $NAME.fastq.gz

Additional info:

File names vary in the first 6 characters but have regular suffixes:

xx-nnn_regular.txt

Files are located in directories named after the first six characters:

xx-nnn > xx-nnn_regular.txt

I have looked in the Perl manual but I do not have a programming background, will someone please help me out?

How do I run a Perl script on multiple input files with the same extension? I used the info here to answer my question-- thanks!

  • 3
    You should read https://perlmaven.com/open-and-read-from-files and the following chapter. You should also take a look at https://perlmaven.com/argv-in-perl if you want to read the filenames from the command line, or into [File::Find::Rule](https://metacpan.org/pod/File::Find::Rule) if you want an easy way to find the files you need based on some rules. – simbabque May 08 '18 at 15:26
  • Do you mean reading the file name from the command line, or base it on the 'current path'? – Sobrique May 08 '18 at 16:05
  • 3
    *Stack Overflow* isn't really the place to get a from-scratch Perl tutorial. – Borodin May 08 '18 at 16:33
  • Yes, I want to base the input file name on the current path. Thanks! – Ginger Geiger May 08 '18 at 18:18

1 Answers1

0

When I was converting a fq file into fa file I would have to open a dynamic file for writing. I had the file I was trying to convert as a command line argument and thus the code responsible was like this.

 my $directory = "output";
 if ($ARGV[0] =~ /^(\S*).fq/) {
     $location = $1;
 }
 open (OUTPUT, ">$directory/$location.fa");

You can just utilise variables within the opening of your file.

This code should dynamically open files for you but the way you input the files will no doubt be different than my solution.

Hope this helps.

Greg Warren
  • 41
  • 1
  • 5