CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
string manipulation

 



mumshquat
New User

Jan 29, 2011, 1:47 PM

Post #1 of 2 (460 views)
string manipulation Can't Post

Sorry if this is a re-post, but I've spent an hour searching through the forums, and haven't found what I'm looking for yet. I am extracting information from a file that has a big ugly table in it that looks something like:

15.0000p 39.570m 2 + + + + + + + +
16.0000p 44.642m 2 + + + + + + + +
17.0000p 49.713m ba + + + + + + + +
18.0000p 54.785m ba + + + + + + + +
19.0000p 59.856m ba + + + + + + + +
20.0000p 64.928m-ba-----+------+------+------+------+------+------+------+-

for about 60k entries or more. I am trying to get the data from the first 2 columns, but as you can see on the line that starts with 20.0000p the second column can get blended in with the stuff going on on the right side. I am unable to figure out a good method for ignoring the characters a,b,-,and+ when I extract that information.

Can anyone point me in the right direction?


FishMonger
Veteran / Moderator

Jan 29, 2011, 3:00 PM

Post #2 of 2 (453 views)
Re: [mumshquat] string manipulation [In reply to] Can't Post


Code
#!/usr/bin/perl 

use strict;
use warnings;

while( my $line = <DATA> ) {
my $fld1 = substr($line, 0, 8);
my $fld2 = substr($line, 9, 7);

print "$fld1,$fld2\n";
}

__DATA__
15.0000p 39.570m 2 + + + + + + + +
16.0000p 44.642m 2 + + + + + + + +
17.0000p 49.713m ba + + + + + + + +
18.0000p 54.785m ba + + + + + + + +
19.0000p 59.856m ba + + + + + + + +
20.0000p 64.928m-ba-----+------+------+------+------+------+------+------+-



(This post was edited by FishMonger on Jan 29, 2011, 3:01 PM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives