G
Gary Schenk
I'm a very new user of Perl, trying to convert the output
of an old DOS program to a CSV format to import to
Microstation. This idea should work, but it won't and
I'm stumped. The substitution pattern to remove the
leading whitespaces comes from the llama book, yet
I seem to be implementing it wrong. It is probably
so obvious that I can't see, so I am hoping another
set of eyes can help. Here it is:
!/usr/bin/perl -w
##############################
# Convert a gcogo EXPORT #
# COORDINATES output file #
# to a Microstaion PLTPNT #
# MDL friendly format #
##############################
print "Convert gcogo EXPORT COORDINATES output\n";
print "to a comma delimited file, for export to\n";
print "PLTPNT in Microstation.\n";
print "\n\n";
print "Enter the name of a file to convert: ";
chomp( $output_file = <STDIN> );
open( FILE, "$output_file") or die( "Can't open that file: $!");
open( CONVERT, "+>converted.txt") or die( "Can't open a conversion file: $!");
# opening a filehandle for update. This is OK, right?
foreach (<FILE>) {
if ( /^\s+\d+/ ) {
print ( CONVERT );
}
}
# This works just fine, apparently. It produces a file with the
# letters stripped out.
close( FILE ) or die( "Can't close that file: $!");
foreach (<CONVERT>) {
s/^\s+//; # From the llama book. It should strip the
# the leading whitespaces, leaving number fields
# separated by whitespaces. However the file produced
# is empty
}
close( CONVERT ) or die( "Can't close converted file: $!");
# There is more work to be done, but I'm stuck here. The plan
# is to use another foreach loop to substitute a comma for white-
# spaces.
Here is an example of the file to be converted:
Wed, Jul 14, 2004, 2:59 PM 54
EXPORT COORDINATES
2-205
3 678772.5350000 1839644.3330000 .0000000
4 678777.8420000 1838819.8640000 .0000000
100 678920.7180000 1838881.9720000 .0000000
101 678891.1930000 1838881.7560000 .0000000
102 678777.4864933 1838880.9241421
103 678777.7542000 1838839.6498000 .0000000
104 678786.8979393 1838839.7196468
105 678786.6895588 1838871.8472255
106 678891.2598942 1838872.6122447
107 678790.6481667 1838871.8761860
108 678790.6771513 1838867.9142920
109 678786.7152346 1838867.8885949
110 678786.7996421 1838854.8748686
111 678792.9937615 1838839.7662113
112 678792.8955139 1838854.9144066
113 678810.9942363 1838839.9037124
114 678831.8116290 1838840.0627314
115 678810.7636285 1838872.0233474
116 678831.5810714 1838872.1756443
117 678789.9458443 1838839.7429290
118 678789.9499268 1838838.8229380
119 678549.9651623 1837934.3833071
120 678928.4725482 1838790.1495672
200 678794.9150526 1838871.9074018
201 678791.0665523 1838854.9025439
202 678790.9821449 1838867.9162702
203 678791.1456251 1838842.7108004
204 678792.3847792 1838839.7615594
205 678793.0051731 1838838.0067278
END OF JOB
Table 39:Unprotected Figure Area 68 Coordinate Area 3619
Job 0 0 Completed 0 Errors
Thanks in advanced for taking a look.
of an old DOS program to a CSV format to import to
Microstation. This idea should work, but it won't and
I'm stumped. The substitution pattern to remove the
leading whitespaces comes from the llama book, yet
I seem to be implementing it wrong. It is probably
so obvious that I can't see, so I am hoping another
set of eyes can help. Here it is:
!/usr/bin/perl -w
##############################
# Convert a gcogo EXPORT #
# COORDINATES output file #
# to a Microstaion PLTPNT #
# MDL friendly format #
##############################
print "Convert gcogo EXPORT COORDINATES output\n";
print "to a comma delimited file, for export to\n";
print "PLTPNT in Microstation.\n";
print "\n\n";
print "Enter the name of a file to convert: ";
chomp( $output_file = <STDIN> );
open( FILE, "$output_file") or die( "Can't open that file: $!");
open( CONVERT, "+>converted.txt") or die( "Can't open a conversion file: $!");
# opening a filehandle for update. This is OK, right?
foreach (<FILE>) {
if ( /^\s+\d+/ ) {
print ( CONVERT );
}
}
# This works just fine, apparently. It produces a file with the
# letters stripped out.
close( FILE ) or die( "Can't close that file: $!");
foreach (<CONVERT>) {
s/^\s+//; # From the llama book. It should strip the
# the leading whitespaces, leaving number fields
# separated by whitespaces. However the file produced
# is empty
}
close( CONVERT ) or die( "Can't close converted file: $!");
# There is more work to be done, but I'm stuck here. The plan
# is to use another foreach loop to substitute a comma for white-
# spaces.
Here is an example of the file to be converted:
Wed, Jul 14, 2004, 2:59 PM 54
EXPORT COORDINATES
2-205
3 678772.5350000 1839644.3330000 .0000000
4 678777.8420000 1838819.8640000 .0000000
100 678920.7180000 1838881.9720000 .0000000
101 678891.1930000 1838881.7560000 .0000000
102 678777.4864933 1838880.9241421
103 678777.7542000 1838839.6498000 .0000000
104 678786.8979393 1838839.7196468
105 678786.6895588 1838871.8472255
106 678891.2598942 1838872.6122447
107 678790.6481667 1838871.8761860
108 678790.6771513 1838867.9142920
109 678786.7152346 1838867.8885949
110 678786.7996421 1838854.8748686
111 678792.9937615 1838839.7662113
112 678792.8955139 1838854.9144066
113 678810.9942363 1838839.9037124
114 678831.8116290 1838840.0627314
115 678810.7636285 1838872.0233474
116 678831.5810714 1838872.1756443
117 678789.9458443 1838839.7429290
118 678789.9499268 1838838.8229380
119 678549.9651623 1837934.3833071
120 678928.4725482 1838790.1495672
200 678794.9150526 1838871.9074018
201 678791.0665523 1838854.9025439
202 678790.9821449 1838867.9162702
203 678791.1456251 1838842.7108004
204 678792.3847792 1838839.7615594
205 678793.0051731 1838838.0067278
END OF JOB
Table 39:Unprotected Figure Area 68 Coordinate Area 3619
Job 0 0 Completed 0 Errors
Thanks in advanced for taking a look.