in reply to Confused when reading Input within Perl and Shell Scripts

Where will the file names come from? Will you provide a file containing the names? Do you want to process all the files in a given directory? Do you want to hard wire the list of names in the Perl script? For the moment lets assume you have resolved that issue and have an array @filenames that contains the names of the files to process. You could then:

for my $filename (@filenames) { open my $dsspIn, '<', $filename or die "Unable to open $filename: +$!\n"; #Create a new DSSP object my $dssp_obj = Bio::Structure::SecStr::DSSP::Res->new ('-file'=> $ +dsspIn); ... close $dsspIn; }

Perl reduces RSI - it saves typing

Replies are listed 'Best First'.
Re^2: Confused when reading Input within Perl and Shell Scripts
by InfoSeeker (Novice) on Nov 16, 2008 at 23:17 UTC

    Thank you. Initially I want to provide a txt file with the filenames, for example, DsspCodes.txt:

    2bx2.dssp 3cob.dssp 1nwn.dssp

    Based on your comments and my novice use of perl, I have modified the code to:

    use strict; use warnings; use Bio::Structure::SecStr::DSSP::Res; my @filenames; for my $filename (@filenames) { open my $dsspIn, '<', $filename or die "Unable to open $filename: $!\n +"; #Create a new DSSP object my $dssp_obj = Bio::Structure::SecStr::DSSP::Res->new ('-file'=> $dssp +In); .... close dsspIn; }

    But if call in the commandline:

     DSSP_output.pl DsspCodes.txt

    I don't get any errors but I also don't get any output??

    Thanks for your patience as I learn this..

    InfoSeeker

      Think about how the contents of the external file containing the file names are going to get into the @filenames array. At present your code has nothing to do that. One way would be:

      my $namesFileName = shift; # Get name of the file names file from comm +and line open my $inNames, '<', $namesFileName or die "Unable to open $namesFil +eName: $!\n"; my @filenames = <$inNames>; # Read the file names (one per line) close $inNames; chomp @filenames; # Remove the line end character from each entry ...

      or you could replace the for loop with a while loop and eliminate the array:

      use strict; use warnings; my $namesFileName = shift; # Get name of the file names file from co +mmand line open my $inNames, '<', $namesFileName or die "Unable to open $namesFil +eName: $!\n"; while (<$inNames>) { chomp; # Remove line end character from file name open my $dsspIn, '<', $_ or die "Unable to open $_: $!\n"; ... } close $inNames;

      Perl reduces RSI - it saves typing