Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now!
  #1  
Old February 7th, 2001, 12:39 PM
dark_jurmanji dark_jurmanji is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Location: Denver, CO
Posts: 0 dark_jurmanji User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 56 sec
Reputation Power: 0
Send a message via ICQ to dark_jurmanji
Angry

Guidance for data manipulating

Now that I have it in one line I just have to ask what is the best way to make this data into a line containing 8 elements. My data looks like this.

code:
2,0|01-24-2001
2,1|1300
2,2|BB02SO
2,3|1
2,4|BLVBB
2,5|BB01-BB06
2,6|BLV
2,7|N/A
2,8|N/A
3,0|01-24-2001
3,1|1730
3,2|ZK51024
3,3|1
3,4|DENZK
3,5|ZK51
3,6|DEN
3,7|39528
3,8|020101
4,0|01-24-2001
4,1|1730
4,2|ZM53024
4,3|1
etc...

[\code]

I used the module that extracts data from an excel spreadsheet and writes it to a file. This is the format that it comes out in. I am trying to get the every nine lines of data into one line, or store every nine lines into a list of strings so that I can insert that data into a MySql database. I am really puzzled about how to get my loop to do this from the format that is shown above or I can also make a file that has one line seporated by a tab or any charater I choose.

My loop looks like this:
Code:
while($line=<MYFILE>)                          
{                                              
        @row_num=split(/\|/, $line);           
        $data1=$row_num[0];                    
        @col_num=split(/,/, $data1);           
        $data2=$col_num[1];                    
        $row_num[1]=~ s/^\s*(.*?)\s*$/$1/;     
                if ($data2 == 0)               
                {                              
                        $row_num[1]=$stardate; 
                }                              
                if ($data2] == 1)        
                {                              
                        $row_num[1]=$startime; 
                }                              
                if ($data2 == 2)        
                {                              
                        $row_num[1]=$sessname; 
                }                              
                if ($data2 == 3)        
                {                              
                        $first1[1]=$irnum;
                }
       ETC......

                if ($data2 ==8)
                {
                        $OK=1;
                        $row_num=$rundate;
                        if($OK ==1)
                        {
                            execute "insert into database";
                        }
                   $Cnt=0;
                 }
            $Cnt++;
    }


will this work?

Does Any one have a thought?


Reply With Quote
  #2  
Old February 7th, 2001, 09:28 PM
mickalo's Avatar
mickalo mickalo is offline
Ole` Timer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2000
Location: N.W. Iowa
Posts: 469 mickalo User rank is Private First Class (20 - 50 Reputation Level)mickalo User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 5 h 19 sec
Reputation Power: 8
Send a message via AIM to mickalo Send a message via MSN to mickalo
If I'm reading your message correctly I think something like this would probably work to get the results your looking for. The $input file would contain the data you've shown in your example. The $output file would be the re-formatted data with the tab delimit, with 8 entries pre line.

=================================
my $input = "/path/to/input_file";
my $output = "/path/to/output_file";

open(FILE,"<$file_a") || die $!;
@lines = <FILE>;
close (FILE);
my $i=0;
open (NEWFILE,">$file_b") || die $!;
foreach $line (@lines) {
chomp $line;
# set to 7 as this is the 8th field
if ($i < 7) {
# print data to output file
print NEWFILE "$line\t";
# increment counter by 1
$i++;
} else {
print NEWFILE "$line\n";
# Reset counter
$i = 0;
}

}
close (NEWFILE);
=============================

Hope this helps

Mickalo

[Edited by mickalo on 02-07-2001 at 08:32 PM]
__________________

Thunder Rain Internet Publishing

Custom Programming & Database development
Providing Personal/Business
Internet Solutions that work!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Guidance for data manipulation


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway