in reply to Re^2: Geo::Shapefile::Writer help
in thread Geo::Shapefile::Writer help

If just one array of (x1,y1,x2,y2...) the easiest way would be to use List::Util
use List::Util qw(pairmap); my @coords = (86.925, 27.988, 86.5278, 27.744, 86.43, 27.365); my @pairs = pairmap { [ $a, $b ] } @coords; $shp_writer->add_shape( \@pairs, @attributes );

Replies are listed 'Best First'.
Re^4: Geo::Shapefile::Writer help
by kjslover (Initiate) on Jan 29, 2016 at 14:58 UTC

    tangent, thank you, that makes perfect sense. I have tried the following code and am now getting an error regarding "Can't use string ("0") as an ARRAY ref while "strict refs" in use at <path to writer.pm> line 141". I have tried adding the use strict; and declaring $x/$y/$dummy, but did not help.
    The following code is what I am using to try to get it to work:

    use Geo::Shapefile::Writer; use List::Util qw(pairmap); $shape = Geo::Shapefile::Writer->new("Temp", 'POLYGON', [COL1 => 'C', +10],); my @coords = (0, 0, 0, 1, 1, 1, 1, 0, 0, 0); my @pairs = pairmap { [ $a, $b ] } @coords; # Checking to make sure pairs look correct foreach $dummy (@pairs) { ($x, $y) = @$dummy; print "$x, $y\n"; } $shape->add_shape(\@pairs, {Col1 => "Dumb1"}); $shape->finalize();