using substr... is this efficient

From: Larry Sandwick (lgs_at_sarreid.com)
Date: 02/20/04


To: <beginners@perl.org>
Date: Fri, 20 Feb 2004 14:14:58 -0500

I have a scripted I wrote that uses *substr* on a file that has fixed
fields. I have to parse the file before I upload into MYSQL.

 

Is there a more efficient way other than *substr*, I looked a *pack* and
*unpack* . it did not make any sense to me.

 

Here is my code, and any suggestions, comments would be appreciated!!!

#-----------------------------------------------

 

#!/usr/bin/perl -w

# Sample input file

# 304 THE CASTLE TWO DRAWER CHEST 6-168 02/18/04

# 751 FRUIT STILL LIFE PLANTER 6-22 02/18/04

# 1029 GLASS TOP: 24" DIA X 1/2" ---- 02/18/04

 

$pvr = 'DISCSL.txt';

$out = 'DISCSL_out.txt';

 

open FILE, "<$pvr" or die "Unabel to open the file\n";

open DATA, ">$out" or die "Unabel to open the file\n";

      

while(<FILE>)

      {

      $the_line = $_;

      chomp($the_line);

 

            $item = substr($the_line,0,10);

            $ldesc = substr($the_line,11,40);

            $page = substr($the_line,52,6);

            $d = substr($the_line,59,8);

 

      # Remove all spaces we do not need !!!

      $item =~ s/\s+// ;

      $page =~ s/\s+// ;

 

       if ( $page eq "----" ) { $page = "" };

      print DATA "$item|$ldesc|$page|$d\n";

 

}

 

close FILE;

close DATA;

 

exit;

 

Larry Sandwick

Sarreid, Ltd.

Network/System Administrator

phone: (252) 291-1414 x223

fax : (252) 237-1592

 



Relevant Pages

  • Re: How do I Exchange data with web server
    ... You can't open that file over http. ... address of the hosted web site. ... I was/am suggesting that you connect to the mysql database via odbc, ... working to upload a csv file and populate the MySQL table. ...
    (microsoft.public.access.forms)
  • Re: Document Library
    ... Dave White wrote in message ... > I would like to do this with PHP / MySQL, but as a relative newbie I ... A file upload system. ... I heartily suggest reading the relevent sections of the manual, ...
    (comp.lang.php)
  • Re: OFFICIAL "WATER IS WIDE" THREAD
    ... As I said in another message in another thread, getting an upload ... If your site has PHP available I could code a simple automatic ... I'd password protect it and you can change that for your own control and ... MySQL is available, but I think all that might get to be overkill. ...
    (rec.music.makers.guitar.acoustic)
  • Re: uploading file and then adding filename to mysql
    ... to create a national Craigslist type ad program which users will be ... able to upload .jpeg flyers. ... I have created a random string which renames the ... the mysql name has a different random number. ...
    (comp.lang.php)
  • Re: Uploaded input text files...need options
    ... bruce barker wrote: ... then you need a new serverside upload control. ... about scalability. ... I could read the uploaded file directly into an array and parse through ...
    (microsoft.public.dotnet.framework.aspnet)