Solved

Perl/tk listbox delete specific element

Posted on 2004-10-19
5
499 Views
Last Modified: 2006-11-17
Hi,

I have some tk code like:

$lb_src  = $f->Scrolled('Listbox', -scrollbars => "osoe")->pack(-side => "left");
foreach(@directoryInListing) {chomp $_;
  $listbox_src->insert("end", $_);
}

Grand. Then I have a specific element that I want to delete from the listbox. Order changes everytime (so that rules out ->delete(#, #)) - unless I run yet another check to find the correct ordering. But I'm sure there must be a simpler way to do this.

I want to write something like:
$var = "foo";
$listbox_src->delete('active'); or
$listbox_src->delete('$var');

Is this not possible??
Seems like there is so much room for improvement in tk =)

Thanks for your help.
Best regards,
0
Comment
Question by:noshankus
  • 2
  • 2
5 Comments
 

Author Comment

by:noshankus
ID: 12346034
And I don't want an answer about counting each element into a hash:

foreach(@directoryInListing) {chomp $_;
    $lb_src->insert("end", $_);
    $ohGodHash{$_} = $ohGodNumber;
    $ohGodNumber++;
}

cos I can do that =) Just wondering if there is an easier way.
0
 
LVL 84

Expert Comment

by:ozo
ID: 12346545
An easier way to count each element into a hash is

@ohGodHash{@directoryInListing}=(0..$#directoryInListing};
0
 
LVL 5

Accepted Solution

by:
ITcrow earned 250 total points
ID: 12420301

$listbox->curselection

Returns a list containing the numerical indices of all of the elements in the listbox that are currently selected. If there are no elements selected in the listbox then an empty string is returned.

$listbox->delete(first, ?last?)

Deletes one or more elements of the listbox. First and last are indices specifying the first and last elements in the range to delete. If last isn't specified it defaults to first, i.e. a single element is deleted.
0
 

Author Comment

by:noshankus
ID: 12420909
Ah nice. Close to what I was hoping for, and works well.

Thanks =)
0
 
LVL 5

Expert Comment

by:ITcrow
ID: 12427272
Glad it worked out.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
use perl to insert into MySQL database 9 135
perl script 4 105
Convert grep lines to perl 6 35
Log File Creation with Header and Footer 17 92
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now