Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

postscript way to reverse a data array?

Status
Not open for further replies.

Hemo

Programmer
Apr 9, 2003
190
0
0
US
Is there a (simple) manner to reverse a data array in postscript?

ie:
data [1 2 3 4 5] def
(simple reverse)
yields data being 5,4,3,2,1.

I don't know postscript very well, I have been searching the blue,red, and green books for 'reverse'. I might even be searching for the incorrect term.

The data is 400 numbers, I am currently creating postscript output via perl and am using perl to reverse the data and include it in the postscript file twice, once forwards and once backwards. I'd like to keep the postscript file as possible, and was hoping I could include the data once and have postscript reverse it.
 
No, there is no "reverse" statement. You'll have to code this yourself.

I would use a "for" loop, in combination with the "length" operator.

The idea would be to retrieve items out of the array in reverse order. Keep in mind that arrays are zero-indexed. I haven't tested this, but something like:

Code:
/newArray data length array def
/newArrayIndex 0 def

data length 1 sub -1 0
{
  data exch get
  newArray exch
  newArrayIndex put
  /newArrayIndex newArrayIndex 1 add def
} for

Like I said, I haven't tested that, but the idea is to work backwards through the data array, and put the elements into the newArray starting at 0 and working forward.

Thomas D. Greer

Providing PostScript & PDF
Training, Development & Consulting
 
I'll try that. Thanks for the direction!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top