using substr... is this efficient
From: Larry Sandwick (lgs_at_sarreid.com)
Date: 02/20/04
- Next message: R. Joseph Newton: "Re: Could I put commands in a variable"
- Previous message: Dave Tibbals: "RE: Digest::MD5"
- Next in thread: Paul Kraus: "RE: using substr... is this efficient"
- Maybe reply: Paul Kraus: "RE: using substr... is this efficient"
- Reply: Rob Dixon: "Re: using substr... is this efficient"
- Maybe reply: Luke Bakken: "RE: using substr... is this efficient"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: R. Joseph Newton: "Re: Could I put commands in a variable"
- Previous message: Dave Tibbals: "RE: Digest::MD5"
- Next in thread: Paul Kraus: "RE: using substr... is this efficient"
- Maybe reply: Paul Kraus: "RE: using substr... is this efficient"
- Reply: Rob Dixon: "Re: using substr... is this efficient"
- Maybe reply: Luke Bakken: "RE: using substr... is this efficient"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|