Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #16  
Old December 7th, 2012, 06:33 AM
Laurent_R Laurent_R is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2012
Posts: 511 Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Laurent_R User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 4 Days 19 h 58 m 22 sec
Reputation Power: 405
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;

Reply With Quote
  #17  
Old December 7th, 2012, 10:42 PM
testerV testerV is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2012
Posts: 65 testerV User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 h 35 m 42 sec
Reputation Power: 1
Very impressive Spacebar!
I kind of understand how the code works but I would never write it by myself.
Thank you Spacebar!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Printing next two lines after a match to a file

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap