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:
  #1  
Old April 23rd, 2001, 07:44 AM
randor randor is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Location: Western New York
Posts: 85 randor User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 h 9 m 46 sec
Reputation Power: 8
Send a message via Yahoo to randor
hello,

i am writing a program and i have come to a point where i need to be able to remove 1 item from an array, hence the splice function, but it is not working like it should, so i am hoping someone can explain to me what i could be doing wrong..

the problem i am having is this:

&no_cart unless (open CART_ID, "+<$svrloc/treasures_cart/$from/$me_here.dat"); ##this is the file to be opened
&oops('FLOCK1') unless (flock(CART_ID, LOCK_EX));
@all_of_it = <CART_ID>;##this is where i get all of the data
if (@all_of_it != '') {##as long as there is infact info in the file
$form{'remove_item'}--;##this is a number, it is used to determine which line of info is to be pulled, example :3 means i want the 3rd line pulled from the file (i am aware that it starts at 0, and have accounted for that
chomp $form{'remove_item'};
splice(@all_of_it, $form{'remove_item'}, 1);##remove the selected number
seek(CART_ID, 0, 0);##return to the top of the file
foreach $gr (@all_of_it) {
chomp $gr;
print CART_ID "$gr\n"; ##print to the file each of the remaining lines
print "$gr<br>";##this is printing to the screen for testing purposes


ok, when i run this, it prints to the screen correct, but when i look at the file it doesnt remove the spliced item, and infact adds half of the line it was suppose to remove to the list.

this is what is in the file originally:

item1%%item2|this stuff|here%%my lione
item3%%item2|here is the stuff%% here
test2%%item2|here|not%%i am


is there anything i am doing wrong with the splice??

thank you for any help you can give:
Randor

Reply With Quote
  #2  
Old April 23rd, 2001, 12:42 PM
unobserved unobserved is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Posts: 11 unobserved User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to unobserved
instead of fussing with a splice, why not try reading the number of the line to remove before you open the file, and then only read the line from the file into the array if the line number != the $form{'remove_item'} value.

just a thought.

Reply With Quote
  #3  
Old May 6th, 2001, 09:26 PM
perlcircus perlcircus is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Location: United Kingdom
Posts: 36 perlcircus User rank is Sergeant (500 - 2000 Reputation Level)perlcircus User rank is Sergeant (500 - 2000 Reputation Level)perlcircus User rank is Sergeant (500 - 2000 Reputation Level)perlcircus User rank is Sergeant (500 - 2000 Reputation Level)perlcircus User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 15 h 1 m 25 sec
Reputation Power: 24
Seems like you should be truncating the file somewhere in there. Consider that you are 1) opening a file for read/write, 2) reading all of its content 3) seeking the start of the file, and then 4) writing less content back to the file.

I don't kow if it will solve your problem but certainly you should be clearing the file after 2 and before 4 or else you will get some leftover bits in the file.
__________________
<www.perlcircus.com>

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > splice problem...


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
Stay green...Green IT