Solved

Perl/tk listbox delete specific element

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

759 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