|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
1200+ fellow developers rate and compare features of the top IDEs, like Visual Studio, Eclipse, RAD, Delphi and others, across 13 categories. Enjoy this FREE Download of the IDE User Satisfaction Study by Evans Data Corporation. Download Now!
|
|
#1
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
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); |
|
#3
|
|||
|
|||
|
that doesn't work =(
ugh, this is a pain in the ***! ------------------ rrandels. |
|
#4
|
|||
|
|||
|
>>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. |
|
#5
|
|||
|
|||
|
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 " |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > deleting a line from an array? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|