Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

remove an element of an array

Status
Not open for further replies.

j0nxuser

Technical User
May 4, 2003
31
0
0
US
Need some assistance with an array. For example, I have an array of unique email addresses (thanks to Getopt::Long) and need to send emails to every address in that array via a for loop. That said, before I enter the for loop to send the emails I need to check to see if the email address joe.q.public@anywhere.com exists. If this email address exists I'll need to delete it from the array and then send the email to everyone else in the array.

Is there a remove function? Exists will just tell if something exists, correct? (I want to remove it entirely)

Very simplied version of my array:
@email_addresses = ('joe@schmoe.com','jane@schmoe.com','joe.q.public@anywhere.com');
 
Use a hash instead of an array: the keys will be the email addresses, the values anything you like.
Then it will be just a matter of [tt]delete $email_addresses{'joe.q.public@anywhere.com'}[/tt] (you even don't need to check for existence before).
Then you send to [tt]keys%email_addresses[/tt] .

Franco
: Online engineering calculations
: Magnetic brakes for fun rides
: Air bearing pads
 
In case you ever get into a scenario where all you have is an array - check out the 'splice' function.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top