×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

postscript way to reverse a data array?

postscript way to reverse a data array?

postscript way to reverse a data array?

(OP)
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.

RE: postscript way to reverse a data array?

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
http://www.tgreer.com
http://www.brownfedora.com

Providing PostScript & PDF
Training, Development & Consulting

RE: postscript way to reverse a data array?

(OP)
I'll try that.  Thanks for the direction!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close