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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
Data from a file cont.....


New User

Sep 20, 2004, 1:32 AM

Post #1 of 2 (1248 views)
Data from a file cont..... Can't Post

Alright chaps, thanks for answering my last query, I now have another one which I hope you can help with. I am trying to come to terms with RE's for processing strings.

I have a file with address data that needs to be parsed by my program, the data in the file comes in the following formats




My program needs to read each line and determine if there is a sub-road present, if there is the data in the sub-road field is put into a variable with any data after that put into an address variable.

So far my statement looks like:

if ($line =~ /~/) {
$line =~ /^\*([^~]*)~([^\*].*)/;
$subRoad = $1;
$address = $2;

else {
$line =~ /^\*([^\*].*)/;
$subRoad = "";
$address = $1;
}This manages to parse the first two format types, the third format (*SUB-ROAD~/ANY OTHER DATA) I am struggling on finding the correct statement for. Any help would be greatly appreciated.


Sep 23, 2004, 1:26 AM

Post #2 of 2 (1241 views)
Re: [adam_wood1234] Data from a file cont..... [In reply to] Can't Post

maybe something along these lines will help:

if ($line =~ /^\*~/) { 
$address = $line;
elsif ($line =~ /,/) {
$line =~ /^\*(.+?),(.+)$/;
$subRoad = $1;
$address = $2;

else {
$line =~ /^\*(.+?)~(.+)$/;
$subRoad = $1;
$address = $2;



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

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