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: Need a Custom or Prewritten Perl Program?: I need a program that...:
HELP Deleting Certain Number of Characters

 



pinto106
New User

Jul 20, 2011, 7:13 AM

Post #1 of 3 (6528 views)
HELP Deleting Certain Number of Characters Can't Post

Suppose I have a data file which looks like this EX:

290611, 201917, 4304.3195, N, 07042.6893, W (line 1)
290611, 201911, 4304.319, N, 07042.688, W (line 2)
290611, 201918, 4304.31904, N, 07042.68844, W (line 3)
290611, 201916, 4304.3196, N, 07042.6893, W (line 4)

Notice that in the third column, (the 4304....) either has 3,4 or 5 decimal places, or 8,9, or 10 characters (4304.3195 has 9 characters).
I need a program that will say if column 3 is not 9 characters then ignore the entire line. So in the ex above it should ignore lines 2 and 3 completely, because for instance line 2, column 3 has 10 characters, and line 3, column 3 has only 8 characters

*Ignore spaces between columns as characters that was only so it was easier to understand. Normally theres no spaces, a line looks like
290611,201916,4304.3196,N,07042.6893,W


FishMonger
Veteran / Moderator

Jul 20, 2011, 10:23 AM

Post #2 of 3 (6525 views)
Re: [pinto106] HELP Deleting Certain Number of Characters [In reply to] Can't Post

What have you tried?

For this task you'd use the length() function.

Inside the loop that processes the file, you'd have a line like this:

Code
next if length($col3) != 9;



miller
User

Jul 22, 2011, 9:31 PM

Post #3 of 3 (6441 views)
Re: [pinto106] HELP Deleting Certain Number of Characters [In reply to] Can't Post

Use Text::CSV for processing csv files.

Then use the length function as advised by Fishmonger.

- Miller

 
 


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

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