horizontal join of array elements

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

Threaded View
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

Re: horizontal join of array elements

Newsgroups: comp.lang.perl.misc
Subject: Re: Generate Squential Numbers?
Date: Wed, 8 Dec 2004 14:25:58 +1100
Lines: 16
X-Trace: individual.net EmMGeAOA34BUx9QyGrTPJgFi3TrbOyy34R4fijqYm7MM3XLpw=
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
Xref: core-easynews comp.lang.perl.misc:430154

Re: horizontal join of array elements

Newsgroups: comp.lang.perl.misc
Subject: Re: horizontal join of array elements
Date: 8 Dec 2004 04:19:21 GMT
Organization: Cornell University
Lines: 26
Sender: asu1@cornell.invalid (on syr-69-202-79-175.twcny.rr.com)
NNTP-Posting-Host: syr-69-202-79-175.twcny.rr.com
X-Trace: news01.cit.cornell.edu 1102479561 22442 (8 Dec 2004
04:19:21 GMT)
X-Complaints-To: usenet@news01.cit.cornell.edu
NNTP-Posting-Date: 8 Dec 2004 04:19:21 GMT
User-Agent: Xnews/06.08.25
Xref: core-easynews comp.lang.perl.misc:430160

Site Timeline