horizontal join of array elements

From: Jorge (awkster_at_yahoo.com)
Date: 12/08/04

  • Next message: Jorge: "horizontal join of array elements"
    Date: 7 Dec 2004 18:33:39 -0800
    
    

    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
    retained.

    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;

    while(<FILE>){
    if(/initial|terminal/){
    $clean_string = cleanser("$_");
    push(@arr, "$clean_string");
    }
    elsif(/polygon|attribute/){
    $clean_string = cleanser("$_");
    push(@arr, "$clean_string");
    }
    $arr = join(" ", @arr);
    print "$arr";
    @arr = (); $arr = "";
    }

    close(FILE);

    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
               .
               .


  • Next message: Jorge: "horizontal join of array elements"

    Relevant Pages

    • horizontal join of array elements
      ... each vertex listed vertically on seperate lines. ... So far I have managed to isolate the individual groups (after cleaning ... hopes of joining them on whitespace. ... did wrong with this join command. ...
      (comp.lang.perl.misc)
    • Problem with parsing stdout inside bash script
      ... it's probably a trivial problem, ... Inside a script I need to ... everything before the first tab (whitespace). ... Is there a way to seperate ...
      (comp.os.linux.development.apps)
    • Re: Problem with parsing stdout inside bash script
      ... Bernhard Agthe wrote: ... > everything before the first tab (whitespace). ... Is there a way to seperate ...
      (comp.os.linux.development.apps)