Trevor Morrison wrote: > > Hi, Hello,
> I am new to using Perl to parse a file. What I am trying to do is > parse a file that is made of online orders. I have written some code > using for and if statements that will go through the file line by line > and using regex I try to match the information with the variables so > that I can write it to a MySQL database. This works fine as long as > each order has their information where it is supposed to be? Are the records separated by something or are they all 26 lines long? > Is there an easier way of doing this? Probably, if we could see an example of what the data looks like. > I get half way through processing > the file and the arrays turn to jibberish! I have included my script if > it helps any. TIA > > You should enable warnings and strict to let perl help you find mistakes. use warnings; use strict; > open(Order, "<c:\\maverick\\test2.TXT") || die ("Cannot find the file test2.TXT"); You should include the $! variable in you error message so you know why it failed. > flock(Order,2); You should use the flock constants from the Fcntl module. use Fcntl ':flock'; flock Order, LOCK_EX or die "Cannot flock c:\\maverick\\test2.TXT: $!"; > @miva_orders=<Order>; It is not necessary to read the whole file into memory in order to process the data. > @order_number = (); > @date = (); > @time = (); > @bill_first_name = (); > @bill_last_name = (); > @ship_first_name = (); > @ship_last_name = (); > @emai_address = (); > @phone_number = (); > @phone_number2 = (); > @business_name = (); > @sold_to_street = (); > @bill_to_street = (); > @bill_to_city = (); > @bill_to_state = (); > @bill_to_zip = (); > @ship_to_city = (); > @ship_to_state = (); > @ship_to_zip = (); > @contry = (); > @code = (); > @name = (); > @quantity = (); > @price_each = (); > @shipping_method = (); > @shipping_amount = (); It might make more sense to use a single data structure instead of multiple separate variables. > #shift @miva_orders; > #shift @miva_orders; > print "Arrya[0] is: $miva_orders[0]\n"; > > [EMAIL PROTECTED]; > print "$length\n"; > > for ($n=1; $n<$length; $n=$n+26) { You don't really need the $length variable. for ( my $n = 1; $n < @miva_orders; $n += 26 ) { > print "N : $n and value of $miva_orders[$n]\n"; > > if ($order_number[$n] eq ""){ > > [snip] > > flock(order,8); > close(order); You don't need to unlock the file as closing it will automatically unlock it. Also you are trying to unlock and close a different file handle then the one you opened. John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]