wrapit Perl Code List

This is the Perl code for wrapit, a small Perl formatting program that reads SAS input or SPSS data list statement and outputs them five to a line. This assumes you have Perl available and that it can be found by the "env" program. Otherwise you can run the program as perl wrapit.pl (or perl wrapit5.pl).

If you want a different output format, just modify the printf command. Or modify the "for" statement if you want a different number of columns (i+=5). Since it currently does 5 columns the program was called wrapit5.

This utility is part of a collection of more text-processing tools.


#!/usr/bin/env perl

# Wrapit: Read input or data list statements (e.g. "VAR1 12-18 .4", one
# line at a time and output them in wrapped format, five to a line
#  Kent Nassen, 4/22/97 & 8/15/97

# Sample input:
#  V1 1-4
#  V2 5-8
#  V3 9-9
#  V4 10-13
#  V5 14-14
#  V6 15-16
#  V7 17-17
#  V8 18-19
#  V9 20-21

# Sample output:
#   V1 1-4                   V2 5-8                   V3 9-9                   
#   V4 10-13                 V5 14-14                 V6 15-16                 
#   V7 17-17                 V8 18-19                 V9 20-21

# Read the input statements into an array
while (<>) {           # read from file on commandline
  chop;                # drop line ends
  for ($_) { s/^\s+//; s/\s+$//; } # strip leading & trailing blanks
  push @elements, $_;  # build array
  }

# Print out the array elements in preferred order & format
   for ($i=0; $i<=$#elements; $i+=5) {  # we want a 5-wide listing
      printf("   %-15s%-15s%-15s%-15s%-s\n",${elements}[$i],${elements}[$i+1],
		${elements}[$i+2],${elements}[$i+3],${elements}[$i+4]); 
   }


Back to the wrapit Page
Last Modified: Sun Jun 14 11:02:46 EDT 2026