I have a test.csv file with multi line in one field like following:
Name, message
"Gus", "See you"
"Amy", "take to you later,
Thank you.
call me"
"Mark", "Try it again
Okay"
Here is my code: -
open(CSV, "test.csv") or die "Cannot open test.csv for read\n";
-
my $string = <CSV>;
-
-
while (<CSV>)
-
{
-
chomp;
-
my @list = split (",");
-
foreach @list;
-
print "$list[0] <$list[1]>\n";
-
-
}
-
It read first record right, but not the second and third ones. Can someone give me some advice how to read this csv file?
Thanks a lot!!!!
1 4854
You shouldn't use "chomp" as your first command, or you will delete the needed newline-character inside your message.
Step 1.) get the next line
Step 2.) Count the number of double quotation marks inside this line
Step 3.) If there are four, you are done with the current record and can split by comma. Then chop and trim the double quotation marks on both ends. Process the resulting record data and go to step 1.
If there are less than four, you should not trim or chop or process. Instead, read the next line and concatenate it with the old. Then go to step 2.
If there are more than four, you should print out an error (too many columns) and exit the loop.
I am not sure if there could be a double quotation mark inside the message, probably escaped by a backslash or so. If so, then you need to count only the the double quotation marks without that slash in front.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: stax |
last post by:
Hello,
can somebody tell me how to serialize/deserialize
a object containing a multi line string using the
XmlSerializer class. One of the both windows
linefeed chars get dumped somewhere down the road.
It would be awesome somebody could answer this,
sadly most of my questions don't get answered.
Regards,
|
by: Jow Blow |
last post by:
I am trying to make a word wrap type function for a multi line text box
field that will be saved to a text file. The word wrap property looks good
in the app but when saved to a text file the line goes on and on where there
is not a new line character in the text box.
Here's kinda what I'm looking at:
//start snippet
public void WrapIt()
{
|
by: John Carnahan |
last post by:
I have a problem writing the text from a multi-line textbox to the Sql
Server db.
If the user sends a vbcrlf (enter key) in the middle of the entered text,
the text gets
truncated at the vbcrlf when writting the data to the database. The text
could get rather long.
The dataset has all of the text (including the vbcrlf), but the resulting
table field in the database only ends up with the portion of text before the
|
by: Agnes |
last post by:
Does the textbox in vb.net (alllow input multi-line ??)
In vfp, there is "editbox" , which allow user to input several lines data
and save in the table 'as memo field'
However, I can't find the similar thing in vb.net and sql server (ntext ?)
please help
Thanks
--
..
|
by: pmarisole |
last post by:
I am trying to use the vbscript "split" function on a multi-select
field. I am trying
to do a mass update of several records at a time.
I am getting an error and I'm not sure what to do. Here is the code if
someone could help...
strID = split(request.form("proj"), ", ")
projstat = split(request.form("rojstat"),",")
impr = split(request.form("impr"),",")
idate =...
| |
by: Kaz Kylheku |
last post by:
I've been reading the recent cross-posted flamewar, and read Guido's
article where he posits that embedding multi-line lambdas in
expressions is an unsolvable puzzle.
So for the last 15 minutes I applied myself to this problem and come up
with this off-the-wall proposal for you people. Perhaps this idea has
been proposed before, I don't know.
The solutions I have seen all assume that the lambda must be completely
inlined within the...
|
by: rossum |
last post by:
I want to declare a const multi-line string inside a method, and I am
having some problems using Environment.NewLine.
I started out with:
class foo {
public void PrintStuff() {
const string multiline =
"The first line." + Environment.NewLine +
|
by: ashok0866 |
last post by:
I had created a macro to read data from an excel sheet and write the
values to a text file. I had used "ActiveSheet.Range("GB" & k).Value"
command to read the values from the excel.
The issue is: some cells in the excel sheet is having two lines value
and four lines data, the text file is generating that value in a
single line. (Ex. the cell value in address column is in four lines
and should display in four lines in the text file...
|
by: todWulff |
last post by:
Good day folks.
Let me open with the statement that I am not a C++/C programmer. The environment that I am programming in is ARMbasic, an embedded BASIC targeted toward ARM-based micro-controllers. So why am I posting herein? Well, the ARMbasic environment makes use of a tool borrowed from your folk's environment - CPP. The build details are:
C:\Program Files\Coridium>cpp --version
cpp (GCC) 3.2.3 (mingw special 20030504-1)
Copyright...
|
by: OuTCasT |
last post by:
How does one make a field in a crystal report Multi Line ???
I have 2 fields next to each other for example :
Problem Solution
------------------------------------------------------
The problem is that the problem field text might get too long and it will then overlap the solutions text.
I have the report on landscape for more space but i sometimes get the same problem....
|
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: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |