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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pesky carriage returns

Status
Not open for further replies.

techlord

Programmer
Sep 4, 2001
2
US
how do i keep carriage returns from being reflected in my 'print OUT' file??? i am trying to create a batch file, only the responses are being put on a new line, and we all know that does not work with batch files... here is my script someone HELP!!! i will give you credit in my script
(*script follows)
---------------------------------------------

#!/usr/local/bin/perl

#this is intended to prompt the user for input and dump
#the responses into a batch file that can be used to update
#or restore the route table. if the route table is built using this
#script then it can be restored simply by running the batch file
#generated by the output.
#
#this script is open source, you can steal it, modify it, just
#do the right thing and give credit to Erich V when using it.
#
#the only requirements are: windows 2000 box and the PERL runtime
#files installed... have fun! bug reports to erichv123@hotmail.com
#
#-------------------------------

#display welcome message

print "\nWelcome to the route-table builder. \nThis will prompt you for information to build your route-table. \nAfter the program terminates, run the batch file that it creates to install \nyour route-table. Restoring the table is as simple as running the batch file \nagain.\n\n";

#ask the user what they wanna name their file

print "\nEnter a name for the batch file that will be created: ";

$file = <STDIN>;

#assign the name of the file given by the user as the OUT variable to write to

$OUT = &quot;$file&quot;;

#ask the user if the route is to be persistent

print &quot;Will this entry be a persistent route? (Y|N)&quot;;

$persist = <STDIN>;

#ask the user what network is the destination network

print &quot;Enter the NETWORK IP ADDRESS of the destination network (ie. 192.168.1.0): &quot;;

$dest = <STDIN>;

#ask the user for the netmask

print &quot;Enter the SUBNET MASK of the DESTINATION NETWORK (ie. 255.255.255.0): &quot;;

$mask = <STDIN>;

#ask the user for the gateway

print &quot;Enter the DEFAULT GATEWAY used to get to the DESTINATION NETWORK (ie. 192.168.1.1): &quot;;

$gw = <STDIN>;

#ask the user for the metric

print &quot;Enter the METRIC (COST) of this route (ie. 1): &quot;;

$metric = <STDIN>;

#stop talking to the user, they do not know wtf they are talking about anyway

#get the persist variable and assign a -p or nothing to it

if ($persist==&quot;y&quot;) {
$p = &quot; -p&quot;;
} else {
$p = &quot;&quot;;
}

#finally, open (or create) the batch file

open OUT, &quot;>>$OUT&quot;;

#write to the batch file

print OUT &quot;route$p add $dest $mask $gw $metric&quot;;
 
here is the output of the script:

route -p add
192.168.1.0
255.255.255.0
192.168.1.1
1


the desired output is:

route -p add 192.168.1.0 255.255.255.0 192.168.1.1 1
 
You could try chomping the input to remove the \n at the end of it. i.e.:
Code:
$dest = chomp <STDIN>;
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top