473,659 Members | 2,666 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Saving a Form to a file

5 New Member
Hi i am trying to write a perl script to save a form to a file. Can anyone help?
Jul 21 '08 #1
10 1378
numberwhun
3,509 Recognized Expert Moderator Specialist
Sure, but we have to know things like:
  1. what you have tried thus far
  2. what errors you are seeing
  3. what is not working

If you can post your code (surrounded by code tags please) and provide us the other information, we will do our best to help you.

Regards,

Jeff
Jul 21 '08 #2
nmeliasp
5 New Member
i was able to save it to a file but now i just want to read in the file and just print out the data on a new line for each element. here is the code: i want the output to look exactly like how it is saved in the file
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use CGI qw(:standard);
  5. use CGI qw(:cgi);
  6.  
  7.  
  8. my $data_file = "/tmp/results.txt";
  9. my $configuration;
  10. my $config_ID;
  11. my $cds_ID ;
  12.  
  13. open (DAT, $data_file) || die ("could not open file");
  14.  
  15. my @raw_data = <DAT>;
  16. close(DAT);
  17.  
  18.  
  19. print "Content-type: text/html \n\n";
  20. print "<html><body>";
  21.  
  22.  
  23.  
  24. print "(@raw_data)";
  25.  
  26.  
  27.  
  28.  
  29. print "</body></html>";
  30.  
*************** *****data from file*********** *************

txtCfgId=test
txtCfguser=test
txtEmailAdr=
txtPager=test
txtSrvOU=test
txtProject=rhga
pnlServerID=eag a
txtSrvrIP=egar
txtSrvrGW=agae
txtSrvrMask=eag a
lstTimeZone=US% 2FCentral
txtDNSDom=aega
txtDNSHold1=efa r
txtDNSHold2=erg ar
txtDNSHold3=
Jul 24 '08 #3
numberwhun
3,509 Recognized Expert Moderator Specialist
nmeliasp,

First, the code tags that I asked you to use to surround your code were not optional. They are required for the forums and your not putting them in requires a moderator to add them for you. Please add them to your code next time, as I requested earlier!

As for your issue, the topic of your post seems to be misleading. It is saying that you want to save a form to a file yet in your latest post, you are wanting to display the contents of a file on the screen, as it appears in the file.

When you run what you have, how does the output look?

Personally, in place of this line:

Expand|Select|Wrap|Line Numbers
  1. print "(@raw_data)";
  2.  
I would write it as so, but this is just me:

Expand|Select|Wrap|Line Numbers
  1. foreach my $line (@raw_data) {
  2.     chomp($line);
  3.     print("$line\n");
  4. }
  5.  
I didn't test it, but that should print out the file, line by line, making it look on the screen as it did in the file.

Regards,

Jeff
Jul 24 '08 #4
nmeliasp
5 New Member
this is the output of the code in an internet browser which is what i want the output to be in:

VTI-GROUP=0 txtCfgId=test txtCfguser=test 1 txtEmailAdr=nme liasp%40yahoo.c om txtPager=test txtSrvOU=test txtProject=rhga pnlServerID=eag a txtSrvrIP=egar txtSrvrGW=agae txtSrvrMask=eag a lstTimeZone=US% 2FCentral txtDNSDom=aega txtDNSHold1=efa r txtDNSHold2=erg ar txtDNSHold3= Submit=Submit =
Jul 24 '08 #5
nmeliasp
5 New Member
it was the same when i tried that piece of code you suggested
Jul 24 '08 #6
numberwhun
3,509 Recognized Expert Moderator Specialist
it was the same when i tried that piece of code you suggested
He he, I didn't even take that into account, sorry, long day. Try this and see if it works:

Expand|Select|Wrap|Line Numbers
  1. foreach my $line (@raw_data) {
  2.     chomp($line);
  3.     print("<p>$line</p>");
  4. }
  5.  
Let me know if that works.

Regards,

Jeff
Jul 24 '08 #7
KevinADC
4,059 Recognized Expert Specialist
this is the output of the code in an internet browser which is what i want the output to be in:

VTI-GROUP=0 txtCfgId=test txtCfguser=test 1 txtEmailAdr=nme liasp%40yahoo.c om txtPager=test txtSrvOU=test txtProject=rhga pnlServerID=eag a txtSrvrIP=egar txtSrvrGW=agae txtSrvrMask=eag a lstTimeZone=US% 2FCentral txtDNSDom=aega txtDNSHold1=efa r txtDNSHold2=erg ar txtDNSHold3= Submit=Submit =
Output in a browser requires HTML markup to display properly. Jeff posted a simple example but this is not the HTML forum. If you need to learn the basics of HTML find an HTML tutorial or read the CGI.pm modules documentation for generating HTML output.


Jeff,

this is not a good example:

Expand|Select|Wrap|Line Numbers
  1. foreach my $line (@raw_data) {
  2.    chomp($line);
  3.    print("$line\n");
  4. }

FIrst it makes little sense to chomp() the input only to add a newline to print the output. But the bigger issue is the use of parenthesis around the argument to the print command. That is really almost never needed, although there are times, when it is, like this:

Expand|Select|Wrap|Line Numbers
  1. print (split(//))[0],"\n";
but if you do that it will print nothing, it will in fact throw a syntax error . You have to use some odd syntax to make it work:

Expand|Select|Wrap|Line Numbers
  1. print ((split(//))[0]),"\n";
or:

Expand|Select|Wrap|Line Numbers
  1. print +(split(//))[0],"\n";
But in this example the newline will not be printed:

Expand|Select|Wrap|Line Numbers
  1. print ((split(//))[0]),"\n";
because the print function expects a list, and the parenthesis create a list, so after the last parenthesis the list ends and the newline is ignored. You have to put the newline inside the parenthesis to make it part of the list. In this example it will print the newline:

Expand|Select|Wrap|Line Numbers
  1. print +(split(//))[0],"\n";
But that is rather obscure syntax and to the unsuspecting perl coder it will look like it should not even work. Hell, I don't even understand why it works but its documented in the print functions manpage.

The best practice is to avoid using parenthesis around the arguments of the print function unless it is really necessary.

Damn, I drank too much coffee this morning.
Jul 24 '08 #8
eWish
971 Recognized Expert Contributor
Damn, I drank too much coffee this morning.
Is this becoming a problem for you?

--Kevin
Jul 26 '08 #9
KevinADC
4,059 Recognized Expert Specialist
Is this becoming a problem for you?

--Kevin
Maybe ............... ...........
Jul 26 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2820
by: Martin Herrman | last post by:
Dear programmers, I have a form: <form action=".." method="post"> <textarea name="text1"></textarea> </form> And a php file that saves this variable to a file:
2
1635
by: Jorge | last post by:
Hello I am just another newbie programmer in PHP and web developping and in the three days I have been messing up with it I have been able to do all the things I wished except one. When I receive variables from a form, like a string with the name I can read them with $_POST without problem. But when the form sends to me a file, I haven't found how to save it into my system. I guess I can access to it with $_POST, fopen it, and then do
7
7522
by: G-Factor | last post by:
Hi all I've just started learning about saving files. I got bit of a problem. The following code gives me an error about incompatible types. (Cannot covert from class character to char *). I would appreciate it if anyone could either help me out, or direct me to an online resource site that has information on saving/loading classes. I have found several tutorials, but they either do not really help (saving text files) or are too...
0
1662
by: Umesh | last post by:
Hi, I have an Application, in which 1) need to post data to a URL(Remote Server), by using HTTPRequest. 2) get the Image data in the form of Stream in Response. 3) need to save this stream as a Image file on the local machine. Giving some code snippet below. RequestAPI = CType(WebRequest.Create(URLName), HttpWebRequest)
6
3281
by: Vijay | last post by:
I need to generate HTML files based on the some codes. One HTML file per code. I have the link (ex:http://123.234.345.456/WebPages/GetTestData.aspx?SomeCode=25), by passing the code as parameter I will get the page displayed. But I don't want to display it, instead save those files in one of the network directories that can be accessed by our third party vended web based application. How can I do this accessing and saving HTML files a...
15
1506
by: Dan DeConinck | last post by:
Hello, I want to save the position of all the controls on my form. I would like to write them out to a preference file. I have done this in DOS BASIC like this: TO WRITE the preference open "c:\preferences.txt" for input as #1 input #1 ,a,b,c
1
1628
by: Tom | last post by:
I have a large application; lots of forms, multiple dynamic DLLs, etc. I also have, in the appliation, a general 'Preferences' class object (which is in itself a separate DLL, and I just include a reference to it so I can instantiate it at the beginning) which stores all my user preferences. I serialize the data to and from an XML file, thereby saving and restoring the user preferences with ease. I also have a Preferences form that the user...
0
1134
by: Umesh | last post by:
Hi Gurus, I have an Application, in which 1) need to post data to a URL(Remote Server), by using HTTPRequest. 2) get the Image data in the form of Stream in Response. 3) need to save this stream as a Image file on the local machine. Giving some code snippet below. RequestAPI = CType(WebRequest.Create(URLName), HttpWebRequest)
0
1390
Ajm113
by: Ajm113 | last post by:
Contributing To: Saving RichTextBox from Tab Control Ok, I have a question what would I use if I wanted to do something like a paste function in a Rich Text Box using the code on that thread? Thanks, Ajm113.
3
2464
by: pozze | last post by:
Hi, I've just made the change from ASP to .net. I have a file (code below) that saves a user submitted file to a MS SQL 2005 database. It collects the file name, file size, file type, and lastly the binary data for the file. I can sucessfully take the files out of the databse again and display them in a data grid. I would like to resize the submitted file to a fixed size (say 180 x 120) before I upload it to the database and do this without...
0
8427
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8330
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8850
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8746
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8626
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7355
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6178
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4334
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.