Page 2 of 2 First 12
  • Jump to page:
    #16
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Posts
    776
    Rep Power
    495
    This could probably made somewhat simpler (avoiding nested while loops) with something like this (quick untested modification to Spacebar's code):

    Code:
    my $out;
    my $outdir  =  '/temp/tmp/';
    my $inf     =  '/temp/tmp/t2';
    my $line;
    
    open ( my $inf_fh, '<', $inf ) or die "Can't open $inf $!\n";
    open (my $out_fh, '>', "dummy.txt" or die "$!\n";
    
    while ( $line = <$inf_fh> ) {
      if ( $line =~ /^Xcoor/) {
        close $out_fh;
        $out  =  substr( $line, 0, -1 );
        $out  =~ s/\s+$//;
        open ( my $out_fh, '>', "${outdir}${out}.txt" ) or die "Can't open ${outdir}${out}.txt $!\n";
      }
      print $out_fh $line;
    }
    close $out_fh;
  2. #17
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    79
    Rep Power
    2
    Very impressive Spacebar!
    I kind of understand how the code works but I would never write it by myself.
    Thank you Spacebar!
Page 2 of 2 First 12
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo