|
Linux's Witness Ministry
The Personal Web Pages of Chris X. Edwards
ex-sprintf.pl |
#!/usr/bin/perl -w
# Chris X Edwards
# This program just reads in data as coordinate pairs and performs
# transformations if the data leads with two columns of numbers The
# format is that lines that begin with "#" are ignored Lines must have
# the format:
# -99999.99999<SPACE>-99999.99999<SPACE>whatever you want....
# Only the first two fields are affected, the first as X, the second
# as Y...
#These variables define how we would like the data transformed.
$XSHIFT=0; # these move the points
$YSHIFT=0;
$XSCALE=1; # these scale the points
$YSCALE=1;
while (<STDIN>) {
$LINE=$_; # Save the input line in case we need it later
# If it's not a comment (#) AND it has the right form
# __1__##2##__3__##4##__5__ then we can play with it
if ( /^ *[^#]/ &&
/([-.0-9]+) *([-.0-9]+) (.*)$/ )
{
# sprintf is used to create rounded values. sprintf conforms to the
# sprintf C function (man sprintf). Notice that it doesn't DO anything
# and that I must set it to a variable to use the results of its
# action.
$XOUT=sprintf ( "%d %d %s\n", (($1+$XSHIFT)*$XSCALE), (($2+$YSHIFT)*$YSCALE), $3 );
print $XOUT;
}
else
# If it's not in a coordinate pair format or it's a comment, then
# ignore it, send it back out untouched
{ print $LINE; }
} # end while
exit
| Return to Program Examples |
This page was created with only free, open-source, publicly licensed software.
This page was designed to be viewed with any browser on any system. |
| Chris X. Edwards ~ June 2003
|