horizontal join of array elements

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Hi, it's me again -- Jorge

My input file is a list of x/y coordinates representing a geometry with
each vertex listed vertically on seperate lines. There are several
shapes in the list and each one always has a START delimiter pattern of
/initial/ and will always have a STOP delimiter of either /polygon/ or
/attribute/. The /terminal/ lines between the delims need to be

I need to gather each set of vertices into a horizontal string
seperated by whitespace.

So far I have managed to isolate the individual groups (after cleaning
them) and then I push the members of each group into an array with the
hopes of joining them on whitespace.

The program works (I think) until I apply the join command at which
time it still returns a vertical listing where I had expected a
horizontal string of all the elements.

I've been through perlfaq5/6 and other places and can not see what I
did wrong with this join command.

Any help is appreciated, Jorge.

Code begins here ....

open (FILE, "file.txt") or die "cant open file: $!";

my @arr;
my $arr;
my $clean_string;

$clean_string = cleanser("$_");
push(@arr, "$clean_string");
$clean_string = cleanser("$_");
push(@arr, "$clean_string");
$arr = join(" ", @arr);
print "$arr";
@arr = (); $arr = "";


sub cleanser{
$_[0] =~ s/$$initial\(\[//g;
$_[0] =~ s/$$terminal\(\[//g;
$_[0] =~ s/\]\, \, \@nosnap \)\;//g;
$_[0] =~ s/\] \)\;//g; s/\]\)\;//g;
return $_[0];

file.txt begins here ...

$$initial([-0.086,0.062], , @nosnap ); # <- START
$$terminal([-0.052,0.062] );
$$terminal([-0.052,0.138] );
$$terminal([-0.061,0.138] );
------- snip ------
$$terminal([-0.061,-0.114] );
$$terminal([-0.052,-0.114] );
$$terminal([-0.052,-0.062] );
$$terminal([-0.086,-0.062] );
$$polygon( "POWER" );        #<- STOP
$$initial([-0.046,-0.022], , @nosnap ); #<- START
$$terminal([-0.012,-0.022] );
$$terminal([-0.012,-0.154] );
$$terminal([-0.021,-0.154] );
-------- snip --------
$$terminal([0.012,-0.154] );
$$terminal([0.012,-0.022] );
$$terminal([0.064,-0.022] );
$$terminal([0.064,0.022] );
$$attribute(...);        #<- STOP
     more of the same

Site Timeline