473,395 Members | 1,595 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,395 software developers and data experts.

splitting a file by a character

3
I got a multiline SQL file that I would like to split by ; and read into an array. However when I try to do
Expand|Select|Wrap|Line Numbers
  1. my @array = split(";", <FH>);
  2.  
and iterate over each element I get just the first line of the SQL file.

Does anyone know how they would get the array of sql statements (and no new lines)?
May 2 '09 #1
4 2351
Icecrack
174 Expert 100+
so far what is all your code or at least how are you reading the next line of the sql file?

have you tried a while loop?
May 4 '09 #2
dafydd
3
I've solved this problem since I last posted here. Thanks for the response though. Here's what I used:
Expand|Select|Wrap|Line Numbers
  1. my $line = "";
  2. my $currentCommand = "";
  3. while(defined($line = <SCHEMA>)) {
  4.     $line =~ s/[\t\n]*//g;
  5.     # append to the current sql command
  6.     $currentCommand = $currentCommand . $line;
  7.     if($line =~ /;/) {
  8.         # this line ends an sql command, execute
  9.         $sth = $dbh->prepare($currentCommand);
  10.         $sth->execute();
  11.         # reset the current line
  12.         $currentCommand = "";
  13.     }
  14. }
  15. close(SCHEMA);
  16.  
May 4 '09 #3
numberwhun
3,509 Expert Mod 2GB
Your code, upon issuing the execute statement, will fetch the first row from sql, but what about each subsequent row? To do that, you will have to incorporate the fetchrow_array method in a loop.
May 13 '09 #4
dafydd
3
@numberwhun
I'm sorry I forgot to mention in the title what those sql statements were. I'm not fetching anything from the database using this code. I'm issuing statements to create sql tables and such to postgresql using the DBI.
May 13 '09 #5

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

Similar topics

5
by: fatted | last post by:
I'm trying to write a function which splits a string (possibly multiple times) on a particular character and returns the strings which has been split. What I have below is kind of (oh dear!)...
2
by: Trint Smith | last post by:
Ok, My program has been formating .txt files for input into sql server and ran into a problem...the .txt is an export from an accounting package and is only supposed to contain comas (,) between...
20
by: Opettaja | last post by:
I am new to c# and I am currently trying to make a program to retrieve Battlefield 2 game stats from the gamespy servers. I have got it so I can retrieve the data but I do not know how to cut up...
10
by: klineb | last post by:
Good Day, I have written and utility to convert our DOS COBOL data files to a SQL Server database. Part of the process requires parsing each line into a sql statement and validting the data to...
7
by: Anat | last post by:
Hi, What regex do I need to split a string, using javascript's split method, into words-array? Splitting accroding to whitespaces only is not enough, I need to split according to whitespace,...
12
by: Simon | last post by:
Well, the title's pretty descriptive; how would I be able to take a line of input like this: getline(cin,mostrecentline); And split into an (flexible) array of strings. For example: "do this...
1
by: samas | last post by:
I am trying to read an XML file and break it up into smaller chunks but am having real problems in doing so as I have never used XML (and am new to C#), so would appreciate any help possible. ...
29
by: Andrea | last post by:
I want to write a program that: char * strplit(char* str1, char *str2, char * stroriginal,int split_point) that take stroriginal and split in the split_point element of the string the string...
2
by: shadow_ | last post by:
Hi i m new at C and trying to write a parser and a string class. Basicly program will read data from file and splits it into lines then lines to words. i used strtok function for splitting data to...
0
by: HughManity | last post by:
I was sent an Excel xls file where the Address column consists of up to 3 address lines stacked on top on each other - all in one cell. If there is more than one line in a cell, then all but the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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...
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...

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.