Solved

Perl/tk listbox delete specific element

Posted on 2004-10-19
5
495 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Check file date before getting folder path 1 64
Regular Expression question to filter with negation. 6 89
Perl File::Find alternative 1 53
Perl Untar File 1 27
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

863 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

20 Experts available now in Live!

Get 1:1 Help Now