The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Perl Programming
|
deleting a line from an array?
Discuss deleting a line from an array? in the Perl Programming forum on Dev Shed. deleting a line from an array? Perl Programming forum discussing coding in Perl, utilizing Perl modules, and other Perl-related topics. Perl, the Practical Extraction and Reporting Language, is the choice for many for parsing textual information.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

July 31st, 2000, 04:18 PM
|
|
Junior Member
|
|
Join Date: Jul 2000
Location: pa, usa
Posts: 8
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.
|

July 31st, 2000, 04:51 PM
|
|
Guest
|
|
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);
|

July 31st, 2000, 08:47 PM
|
|
Junior Member
|
|
Join Date: Jul 2000
Location: pa, usa
Posts: 8
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
that doesn't work =(
ugh, this is a pain in the ***!
------------------
rrandels.
|

July 31st, 2000, 10:22 PM
|
|
Guest
|
|
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.
|

August 1st, 2000, 09:27 AM
|
|
Contributing User
|
|
Join Date: Aug 2000
Location: Indiana
Posts: 614
  
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  "
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|