Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text manipulation help

Status
Not open for further replies.

nogs

Technical User
Aug 3, 2001
89
GB
From a report we use I am trying to select lines join the two lines together - I then need to select chunks from the joined up line to upload to mysql , this is as far as I have got can anyone help??

$se1 = if '^Product Code :';
$se2 = if '^PALLETS ';
while (<FILE>)
{
print /$se1/;
print /$se2/;
} Nogs
[ponder]
 
Tanderso
from a report I want to extract lines beginning with two different criteria where these are found I want to then join them and carry on looking for more occurances to add together.
Once I have all of the lines joined I want to select from the lines (using substr - I think) and upload the data to mysql. Nogs
[ponder]
 
It's still not very clear. But it sounds like a data structure other than a string would be useful.
Code:
my $se1 = &quot;Product Code         :&quot;;    
my $se2 = &quot;PALLETS   &quot;;

my @se1; my @se2;

while (<FILE>)
{
  push @se1, $_ if /^$se1/;
  push @se2, $_ if /^$se2/;
}

for (my $x = 0; $x < scalar @se1; $x++) {...insert in database...}
for (my $x = 0; $x < scalar @se2; $x++) {...insert in database...}
Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
tanderso
the file I want to extract the data from has in it summaries of product codes which can be 6 lines long for each product, the data I require is within 2 lines one begins with Product Code and one with PALLETS. I think it would be easier at this point to join together the two lines for each product? I then want to select from the products line key chunks of data using substr and upload the data to mysql - sorry I hope that is a little clearer. Nogs
[ponder]
 
Concatenating and splitting strings is not the best way to store data. Use a hash or an array or an array of hashes, etc. Please construct a more concise question to get a more detailed answer. I'm willing to help if you're stuck on some specific problem, but if you're looking for someone to write you a whole program, I'd need a contract and a deposit.
Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top