Loading ...
Sorry, an error occurred while loading the content.

Adding quotes to end of array value

Expand Messages
  • Karalius, Joseph
    I m having trouble adding quotes to the end of an array value. There seems to be a newline at the end but I need to add double quotes between the value and
    Message 1 of 2 , May 1 10:35 AM
    • 0 Attachment
      I'm having trouble adding quotes to the end of an array value. There seems
      to be a newline at the end but I need to add double quotes between the value
      and the newline. I've tried chomp/chop but can't seem to get it to work.
      The line in question is marked with *---> (around line 63). I've also
      attached the input file clones.txt

      the output should be like this:

      0 - "marker"
      1 + "clone1"
      2 + "clone 2"
      3 - "marker"

      but I keep getting

      0 - "marker
      "1 + "clone1
      "2 + "clone 2
      "3 - "marker

      #!/usr/bin/perl -w

      use strict;

      # Print title of program
      print "\n\n";
      print "***********************************\n";
      print "* CLONE IMPORT TOOL FOR IMAGE *\n";
      print "***********************************\n";
      print "\n";

      #Determine number of lanes in gel

      print "\nEnter number of lanes in gel: ";
      my $gelmaxlane = <STDIN>;
      chomp $gelmaxlane;
      print "You entered $gelmaxlane.\n";

      #Determine number of lanes between markers

      print "\nEnter spacing of marker lanes: ";
      my $markerspace = <STDIN>;
      chomp $markerspace;
      print "You entered $markerspace.\n";

      #Get filename containing clones in gel

      print "\nEnter filename containing clone names: ";
      my $clone_list = <STDIN>;
      chomp $clone_list;

      # open the file or exit
      unless ( open(CLONES, $clone_list) ) {
      print "Cannot open file \$clone_list\"\n\n";
      }

      print "\nEnter name of file to output to: ";
      my $cloneout = <STDIN>;
      chomp $cloneout;

      # open the file or exit
      unless ( open(CLONEOUT, "+>$cloneout") ) {
      print "Cannot open file \$clone_out\"\n\n";
      }

      my @clonenames = <CLONES>;
      # print @clonenames; #debugging

      my $lane = 0;
      my $clonenum = 0;
      my $marker = $markerspace;
      # print "$marker\n"; #debugging

      print CLONEOUT "NAMES\n"; # print file header
      print "NAMES\n"; # print file header

      while ( $lane < $gelmaxlane )
      {
      print CLONEOUT "$lane ";
      print "$lane ";
      if ( $marker < $markerspace )
      {
      # chomp $clonenames[$clonenum]; #debugging
      # print $clonenames[$clonenum]; #debugging
      *---> my $cline = '+ "' . $clonenames[$clonenum] . '"';
      #chomp $cline; #debugging
      print CLONEOUT "$cline";
      print "$cline";

      $clonenum += 1;
      $marker += 1;
      }
      else
      {
      print CLONEOUT "- \"marker\"\n";
      print "- \"marker\"\n";
      # print "$marker\n"; #debugging
      $marker = 1;
      # print "$marker $markerspace\n"; #debugging
      }
      ++$lane;
      }

      # print summary of file output

      print "\n\n\n****FILE OUTPUT SUMMARY****\n\n";
      print "The gel has $gelmaxlane lanes.\n";
      print "$clonenum clones were entered into file.\n";
      print "Marker lanes are spaced every $markerspace lanes.\n";
      print "Clone names file is $cloneout.\n";
      print "\n\n";

      close CLONES;
      close CLONEOUT;
      exit;


      ----------

      CLC110E5f
      CLC110E5r
      CLC110E7f
      CLC110E7r
      CLC110D10f
      CLC110D10r
      CLC110G5f
      CLC110G5r
      CLC110G7f
      CLC110G7r
      CLC110E10f
      CLC110E10r
      CLC110H5f
      CLC110H5r
      CLC110D8f
      CLC110D8r
      CLC110G10f
      CLC110G10r
      CLC110C6f
      CLC110C6r
      CLC110G8f
      CLC110G8r
      CLC110H10f
      CLC110H10r
      CLC110E6f
      CLC110E6r
      CLC110H8f
      CLC110H8r
      CLC110A11f
      CLC110A11r
      CLC110F6f
      CLC110F6r
      CLC110C9f
      CLC110C9r
      CLC110B11f
      CLC110B11r
      CLC110G6f
      CLC110G6r
      CLC110A10f
      CLC110A10r
      CLC110E11f
      CLC110E11r
      CLC110C7f
      CLC110C7r
      CLC110B10f
      CLC110B10r
      CLC110G11f
      CLC110G11r
      CLC110H11f
      CLC110H11r
      CLC111G1f
      CLC111G1r
      CLC111E3f
      CLC111E3r
      CLC110A12f
      CLC110A12r
      CLC111H1f
      CLC111H1r
      CLC111F3f
      CLC111F3r
      CLC110B12f
      CLC110B12r
      CLC111C2f
      CLC111C2r
      CLC111A4f
      CLC111A4r
      CLC110C12f
      CLC110C12r
      CLC111D2f
      CLC111D2r
      CLC111E4f
      CLC111E4r
      CLC110F12f
      CLC110F12r
      CLC111G2f
      CLC111G2r
      CLC111F4f
      CLC111F4r
      CLC111A1f
      CLC111A1r
      CLC111E2f
      CLC111E2r
      CLC111B5f
      CLC111B5r
      CLC111C1f
      CLC111C1r
      CLC111H2f
      CLC111H2r
      CLC111C5f
      CLC111C5r
      CLC111F1f
      CLC111F1r
      CLC111A3f
      CLC111A3r
      CLC111D5f
      CLC111D5r


      [Non-text portions of this message have been removed]
    • Charles K. Clarkson
      ... FYI: print won t end the program. Try using die instead. Perl will tell you some information about the error if you include its standard error message
      Message 2 of 2 , May 1 2:48 PM
      • 0 Attachment
        Karalius, Joseph <Joseph.Karalius@...> wrote:

        : #!/usr/bin/perl -w
        :
        : use strict;
        :
        : # Print title of program
        : print "\n\n";
        : print "***********************************\n";
        : print "* CLONE IMPORT TOOL FOR IMAGE *\n";
        : print "***********************************\n";
        : print "\n";
        :
        : #Determine number of lanes in gel
        :
        : print "\nEnter number of lanes in gel: ";
        : my $gelmaxlane = <STDIN>;
        : chomp $gelmaxlane;
        : print "You entered $gelmaxlane.\n";
        :
        : #Determine number of lanes between markers
        :
        : print "\nEnter spacing of marker lanes: ";
        : my $markerspace = <STDIN>;
        : chomp $markerspace;
        : print "You entered $markerspace.\n";
        :
        : #Get filename containing clones in gel
        :
        : print "\nEnter filename containing clone names: ";
        : my $clone_list = <STDIN>;
        : chomp $clone_list;
        :
        : # open the file or exit
        : unless ( open(CLONES, $clone_list) ) {
        : print "Cannot open file \$clone_list\"\n\n";
        : }

        FYI:
        'print' won't end the program. Try using 'die'
        instead. Perl will tell you some information about
        the error if you include its standard error
        message $! at the end of the line. Don't put a \n
        after it, though. The most common idioms seem to
        be:

        open(CLONES, $clone_list) || die "Cannot open '$clone_list': $!";

        Or:

        open CLONES, $clone_list or die "Cannot open '$clone_list': $!";


        : print "\nEnter name of file to output to: ";
        : my $cloneout = <STDIN>;
        : chomp $cloneout;
        :
        : # open the file or exit
        : unless ( open(CLONEOUT, "+>$cloneout") ) {
        : print "Cannot open file \$clone_out\"\n\n";
        : }
        :
        : my @clonenames = <CLONES>;

        Go ahead and get rid of the line endings here:
        chomp( my @clonenames = <CLONES> );

        : # print @clonenames; #debugging
        :
        : my $lane = 0;
        : my $clonenum = 0;
        : my $marker = $markerspace;
        : # print "$marker\n"; #debugging
        :
        : print CLONEOUT "NAMES\n"; # print file header
        : print "NAMES\n"; # print file header
        :
        : while ( $lane < $gelmaxlane )
        : {
        : print CLONEOUT "$lane ";
        : print "$lane ";
        : if ( $marker < $markerspace )
        : {
        : # chomp $clonenames[$clonenum]; #debugging
        : # print $clonenames[$clonenum]; #debugging
        : my $cline = '+ "' . $clonenames[$clonenum] . '"';
        : #chomp $cline; #debugging
        : print CLONEOUT "$cline";
        : print "$cline";


        The line endings are gone. Let's put them back:

        my $cline = qq(+ "$clonenames[$clonenum]"\n);
        print CLONEOUT $cline;
        print $cline;

        : $clonenum += 1;
        : $marker += 1;
        : }

        HTH,


        Charles K. Clarkson
        --
        Head Bottle Washer,
        Clarkson Energy Homes, Inc.
        Mobile Home Specialists
        254 968-8328
      Your message has been successfully submitted and would be delivered to recipients shortly.