473,408 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Separating Text Fields by comma

19
Hi,
I have created a text widget with multiple text fields using Perl Tk. So its like a web form e.g

Name: (user entered xyz)
Address:(user entered 123)
Age:(user entered 77)

When a user enters text in the fields and submits it, the data gets copied to a csv file. So the csv file looks like this:

NamexyzAddress123Age77

I want the csv file to look like:

Namexyz,Address123,Age77

How do I get the comma to be added to the text entered by the user

Thanks
Feb 1 '07 #1
11 2037
miller
1,089 Expert 1GB
Where is your code that writes to the file? We can't tell you how to change your code without first seeing what you have.
Feb 1 '07 #2
KevinADC
4,059 Expert 2GB
Where is your code that writes to the file? We can't tell you how to change your code without first seeing what you have.

monkies maybe? :)
Feb 1 '07 #3
jw01
19
Here is the code:

use Tk;

open D, ">form3.csv";

$mw = MainWindow->new;
$mw->title("CR FORM");
$f = $mw->Frame->pack(-side => 'bottom');
$f->Button(-text => "Done",-command => sub {exit})->pack(-side=> 'left', -anchor => 'ne');
$f->Button(-text =>"Submit",-command => sub{print D %info})->pack(-side => 'bottom',-anchor => 'nw');

$t = $mw->Scrolled("Text",-width => 40,-wrap => 'none')->pack(-expand => 1, -fill => 'both');
foreach (qw/Name Address Age/) {
$w = $t->Label(-text => "$_:", -relief => 'groove', -width => 100);
$t->windowCreate('end', -window=> $w);
$w = $t->Entry(-width => 100, -textvariable => \$info{$_})->pack(-side => 'left', -anchor => 'w');
#@info = split(',', $info, 1);
$t->windowCreate('end', -window => $w);
$t->insert('end', "\n");

}
$t->configure(-state => 'disabled');

MainLoop;
Feb 1 '07 #4
KevinADC
4,059 Expert 2GB
Tk is almost like learning a whole new scripting language! Where in that code is the data written to a file?
Feb 1 '07 #5
KevinADC
4,059 Expert 2GB
Oh, I see now:

Expand|Select|Wrap|Line Numbers
  1. -command => sub{print D %info})
Maybe like this:

Expand|Select|Wrap|Line Numbers
  1. -command => sub{print D join(',' %info)})
Feb 1 '07 #6
jw01
19
Well I had tried this earlier:

-command => sub{print D join(',', %info)}

But all it does is separate the enteries in the excel sheet into different cells..It doesnt add a comma.

I want it to be displayed like this:
Name xyz, Address 123, Age gds

where xyz,123 and gds are the enteries in the widget form.

Thanks
Feb 1 '07 #7
KevinADC
4,059 Expert 2GB
if you want a comma in a cell I believe you have to quote the string, try this:

Expand|Select|Wrap|Line Numbers
  1. use Tk;
  2.  
  3. open D, ">form3.csv";
  4. my $cell = qq~"Name $info('Name'},Address $info{'Address'},Age $info{'Age'}"~; 
  5. $mw = MainWindow->new;
  6. $mw->title("CR FORM");
  7. $f = $mw->Frame->pack(-side => 'bottom');
  8. $f->Button(-text => "Done",-command => sub {exit})->pack(-side=> 'left', -anchor => 'ne');
  9. $f->Button(-text =>"Submit",-command => sub{print D $cell})->pack(-side => 'bottom',-anchor => 'nw');
Feb 1 '07 #8
jw01
19
Yes now it adds the comma after each label..But its not reading the input entered by the person in the textbox:

$w = $t->Entry(-width => 100, -textvariable => \$info{$_})->pack(-side => 'left', -anchor => 'w');

Should the $info{$_} be changed?? I have been playing around with this entry and the $cell..but I cannot get it to read the text entry and add the comma after it.

Thanks
Feb 1 '07 #9
KevinADC
4,059 Expert 2GB
Sorry, I have no idea. If you don't get an answer here try asking on the www.Tek-Tips.com perl forum.
Feb 1 '07 #10
jw01
19
previous line:

w = $t->Entry(-width => 100, -textvariable => \$info{$_})->pack(-side => 'left', -anchor => 'w');

Change made

w = $t->Entry(-width => 100, -textvariable => \$info{"," , $_})->pack(-side => 'left', -anchor => 'w');

It now enters a "comma" after writing every input to the csv..But when I open the csv, it says file type for recognized and hence adds an extra "empty box" like element to the string..

How do i get rid of that??

Thanks
Feb 2 '07 #11
KevinADC
4,059 Expert 2GB
this just looks wrong:

Expand|Select|Wrap|Line Numbers
  1. \$info{"," , $_}

I'm surprised that doesn't return an error or warning.
Feb 3 '07 #12

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

Similar topics

22
by: Ram Laxman | last post by:
Hi all, I have a text file which have data in CSV format. "empno","phonenumber","wardnumber" 12345,2234353,1000202 12326,2243653,1000098 Iam a beginner of C/C++ programming. I don't know how to...
5
by: Michael Hill | last post by:
Hi, folks. I am writing a Javascript program that accepts (x, y) data pairs from a text box and then analyzes that data in various ways. This is my first time using text area boxes; in the past,...
1
by: DCM Fan | last post by:
Access 2K, SP3 on Windows 2K, SP4 All, I have an import spec set up with quoted Identifiers and comma-separated values. The text file is produced by a 3rd-party program of which I have no...
13
by: Richard Hollenbeck | last post by:
To prevent future apostrophe bugs and errors, isn't it just simpler to forbid an apostrophe from being entered into a text field? For example, couldn't "Alice's Restaurant" be changed to "Alices...
2
by: Kenneth Koski | last post by:
Hello All, I have a comma delimited text file, which I would like to move into a SQL 2000 table . I created a DTS package in SQL Server and saved it as a VB.bas . I am writting the code in C#...
3
by: Avi | last post by:
I need to create a text file that has the data from the 10 tables in the database. The number of fields in the tables exceeds 255 and so I cannot make a new table with all the fields and then...
13
by: sonald | last post by:
Hi, Can anybody tell me how to change the text delimiter in FastCSV Parser ? By default the text delimiter is double quotes(") I want to change it to anything else... say a pipe (|).. can anyone...
3
by: janetager | last post by:
I have a field that has names in it in the format "last name, first name". I want code that will split this field for me at the comma so I can make 2 separate fields for last name and first name. ...
15
by: pakerly | last post by:
How would i do this, convert a test file to excel? Lets say my text file has fields like this: NUMBER NAME ADDRESS PHONE 11002 Test1 ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...
0
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...
0
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,...
0
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...

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.