Hi i am trying to write a perl script to save a form to a file. Can anyone help?
10 1378 numberwhun 3,509
Recognized Expert Moderator Specialist
Sure, but we have to know things like: - what you have tried thus far
- what errors you are seeing
- 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
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 -
#!/usr/bin/perl
-
-
use strict;
-
use CGI qw(:standard);
-
use CGI qw(:cgi);
-
-
-
my $data_file = "/tmp/results.txt";
-
my $configuration;
-
my $config_ID;
-
my $cds_ID ;
-
-
open (DAT, $data_file) || die ("could not open file");
-
-
my @raw_data = <DAT>;
-
close(DAT);
-
-
-
print "Content-type: text/html \n\n";
-
print "<html><body>";
-
-
-
-
print "(@raw_data)";
-
-
-
-
-
print "</body></html>";
-
*************** *****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=
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:
I would write it as so, but this is just me: -
foreach my $line (@raw_data) {
-
chomp($line);
-
print("$line\n");
-
}
-
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
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 =
it was the same when i tried that piece of code you suggested
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: -
foreach my $line (@raw_data) {
-
chomp($line);
-
print("<p>$line</p>");
-
}
-
Let me know if that works.
Regards,
Jeff
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: - foreach my $line (@raw_data) {
-
chomp($line);
-
print("$line\n");
-
}
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: - 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: - print ((split(//))[0]),"\n";
or: - print +(split(//))[0],"\n";
But in this example the newline will not be printed: - 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: - 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.
eWish 971
Recognized Expert Contributor
Damn, I drank too much coffee this morning.
Is this becoming a problem for you?
--Kevin
KevinADC 4,059
Recognized Expert Specialist
Is this becoming a problem for you?
--Kevin
Maybe ............... ...........
Sign in to post your reply or Sign up for a free account.
Similar topics |
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:
|
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
|
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...
|
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)
|
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...
| |
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
|
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...
|
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)
|
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.
|
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...
|
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...
| |
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,...
|
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...
|
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...
|
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...
|
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...
|
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...
| |
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |