Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

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 July 31st, 2000, 04:18 PM
rrandels rrandels is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Location: pa, usa
Posts: 8 rrandels User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
If i have an array that is multiline like:

ryan c:randels
joe b:frank
travis f:collins

and i want to delete one of those lines, how would i go about it if i don't know the absolute location, all i know is the text.

sorry, i'm self taught.



------------------
rrandels.

Reply With Quote
  #2  
Old July 31st, 2000, 04:51 PM
freebsd
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Use "splice".
Here is an example:

open(DB,"db.txt");
@lines = <DB>;
close(DB);
$count = 0;
foreach $line (@lines) {
chomp $line;
($fullname,$username)=split(/:/,$line);
if ($username eq "$FORM{'username')") {
$username = $1;
last;
}
else {
$count++;
}
}
splice(@lines, $count, 1);
#the following will remove the matched username from db.txt and refresh all lines
open(DB, ">db.txt");
foreach $line (@lines) {
print DB $line;
}
#the following will update a new record
open(DB, ">>db.txt");
print DB "$FORM{'fullname'}:$FORM{'username'}n";
close(DB);

Reply With Quote
  #3  
Old July 31st, 2000, 08:47 PM
rrandels rrandels is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Location: pa, usa
Posts: 8 rrandels User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
that doesn't work =(

ugh, this is a pain in the ***!



------------------
rrandels.

Reply With Quote
  #4  
Old July 31st, 2000, 10:22 PM
freebsd
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
>>that doesn't work =(

This answer doesn't tell me anything either.
Well, just read my code and found one syntax error at -> if ($username eq "$FORM{'username')") {
which should be:
if ($username eq "$FORM{'username'}") {

You need to give more details and be more specific. Simply saying: "Oh no, I've got 500 internal error" tells me nothing.

Reply With Quote
  #5  
Old August 1st, 2000, 09:27 AM
JonLed JonLed is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2000
Location: Indiana
Posts: 614 JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 h 49 m 49 sec
Reputation Power: 14
I'll assume this is to get ride of an entry in a password file. Try this:
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
open(DB, "$pass_file") | | print "Error: $!";
@db = <DB>;
close(DB);

foreach $line (@db) {
($user,$pass) = split(/:/, $line);
if ($FORM{del_name} eq $user) {} else {
$ins_data = $user . ":" . $pass;
push(@insert, $ins_data)
}#End else
}#End forech

open(DB, ">$pass_file") | | print "Error: $!";
flock(DB, 2);
foreach $line (@insert) {
print DB $line;
}#end foreach
flock(DB, 8);
close(DB);
print "Deleted: $FORM{del_name}";
[/code]
del_name is a form item that is used to get the delete info from.

Note: This is "ledjon". The forumd downtime must have really messed with stuff. I used to "Forget your password?" link and it e-mailed me with nothing as my user name and password "

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > deleting a line from an array?

Developer Shed Advertisers and Affiliates



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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap