How to create a variable without multiple concats in a perl scripts that makes a bsub?

The red text at the bottom represents the three lines I want to address.
I'm dynamically creating a bsub with a perl script and would like to create the

fasta_16S

variable in a single line....not three. I'm having difficulty in getting the syntax correct. Obviously, there is some confusion because I'm creating a script in a script.

#!/usr/bin/perl -w


use strict;
use File::Slurp;
use Data::Dumper;




my ($dir,$plugin,$MIN_READ_LENGTH_16S) = @ARGV;
my $microbiome_sample_id_list = $dir . "/sample_ids_of_microbiome_samples.csv";
my $DB="/mnt/Lab/Data/IonTorrent/plugins/" . $plugin . "/db/MB_DB.udb";
my @file = read_file($microbiome_sample_id_list);
my $sample_num = scalar @file;
my $path = "/mnt/Lab/Data/IonTorrent/$server/$run";





open BSUB,">$dir/MB.bsub" || die $!;

       print BSUB "\#!/bin/bash\n

                   \#BSUB -J MBSAMPLE\[1-$sample_num\]
                   \#BSUB -o $path/MBSAMPLE.out
                   \#BSUB -e $path/MBSAMPLE.err\n


                   id=(`sed -n \"\$LSB_JOBINDEX\"p $path/sample_ids_of_microbiome_samples.csv`)

                   fasta_16S=$path/\${id}/\${id}_bacterial_minreadlen
                   fasta_16S+=$MIN_READ_LENGTH_16S
                   fasta_16S+=.fasta

              ";

close(BSUB);

Try string::sprintf():

fasta_16S=sprintf("%s/%s/%s%s%s%s", 
               $path, ${id}, ${id}, $MIN_READ_LENGTH_16S, ".fasta" );

Hi, jdilts

You only need interpolation and you got it already with the double quotes.

print BSUB "
...
...
fasta_16S=$path/\${id}/\${id}_bacterial_minreadlen$MIN_READ_LENGTH_16S.fasta\n";

Notice: I do think you are missing some newlines after what it will become some lines in the bash script.

1 Like

@Aia. omg duh. you are so right.