First put use strict;
at the top of your code and declare your variables.
Secondly, these are:
Not going to do what you want. split () takes a string and turns it into an array. The union takes a list of elements and returns a string. You just want to split:
my @filenames = split(',', $filenames);
This will create the array you expect.
This function will safely trim the space from the beginning and end of the line:
sub trim { my $string = shift; $string =~ s/^\s+//; $string =~ s/\s+$//; return $string; }
Access it as follows:
my $file = trim(shift @filenames);
Depending on your script, it might be easier to pass strings as command line arguments. You can access them through the @ARGV array, but I prefer to use GetOpt :: Long:
use strict; use Getopt::Long; Getopt::Long::Configure("bundling"); my ($qseq_filename, $barcode); GetOptions ( 'q|qseq=s' => \$qseq_filename, 'b|bar=s' => \$barcode, );
Then you can call it like:
./script.pl -q sample1.qseq -b barcode.txt
And the variables will be populated correctly without having to worry about trimming the space.
source share