View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
John Gamble > Array-Tour-0.06 > Array::Tour::Serpentine



Annotate this POD

View/Report Bugs
Module Version: 0.06   Source  


Array::Tour::Serpentine - Return coordinates to take a serpentine path.


  use Array::Tour::Serpentine qw(:directions);

  my $tour = Array::Tour::Serpentine->new(
      dimensions => [5, 5],
      vertical => $vertical,
      corner_right => $corner_right,
      corner_bottom => $corner_bottom);

Creates the object with its attributes. The attributes dimensions, offset, start, and position are inherited from Array::Tour. This package adds more attributes of its own, which are:

counterclock, corner_bottom, corner_right, vertical

Default values: 0. All are boolean values that affect the starting point and the direction of the tour. By default, the tour is generated the upper left corner in a horizontal back-and-forth path.

See the Examples section to see what effects the different combinations produce.


Perl 5.8 or later. This is the version of perl under which this module was developed.


A simple iterator that will return the coordinates of the next cell if one were to tour an array's cells in a serpentine path.

Serpentine Object Methods


  $dir = $tour->direction()

  Return the direction we just walked.

  Overrides Array::Tour's direction() method.


Returns a reference to an array of coordinates. Returns undef if there is no next cell to visit.

Overrides Array::Tour's next() method.


  $ruot = $tour->opposite();

Return a new object that follows the same path as the original object, reversing the inward/outward direction.



  Override Array::Tour's _set() method for one that can handle
  our parameters.

Example: A Serpentine Tour of the Square

The four by four case demonstrates the different possible arrangements. There are four possible central positions. By default, the tour will begin in the top left corner, but the options corner_bottom and corner_right can force the starting point to a different corner of the square.


The :directions and :status EXPORT tags are available, as defined in Array::Tour.

See Also


John M. Gamble may be found at <>

syntax highlighting: