Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Perl/tk listbox delete specific element

Posted on 2004-10-19
5
Medium Priority
?
543 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
Six Sigma Control Plans

610 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