Hi,
first of all I want to say that I could fairly easy replace my second snippet with the opendir/readdir thing. Great!

-MO=Deparse is a very useful thing. Thanks for that.
I was trying to adapt it for my needs but it didn't work as it should.
It simply processes the first record (accessibility) and than hangs.
sub scan { $lb1->insert('end', "Scanning..."); my $counter = '0'; my $file = '/usr/ports/y.lis'; my $outf = '/usr/ports/yyy.lis'; open(ARGV,$file) or die $!; open(OUTF,">$outf") or die $!; BEGIN { $/ = "\n"; $\ = "\n"; } LINE: while (defined($_ = <ARGV>)) { chomp $_; use File::Glob (); foreach $_ (glob("$_/*")) { if (!/Makefile(.inc|)$/) { printf OUTF "$_\n"; } else { $counter++; } } close(ARGV); close(OUTF); print "processed $counter records."; $lb1->insert('end', "Done."); } }
The content of the /usr/ports/y.lis file is as following:
accessibility arabic archivers astro audio ...and about 70 more.
The content of the /usr/ports/yyy.lis file (produced by the code above) is as following:
accessibility/accerciser accessibility/at-poke accessibility/at-spi accessibility/at-spi-reference accessibility/atk accessibility/atk-reference accessibility/dasher accessibility/eflite accessibility/gail accessibility/gail-reference accessibility/gir-repository-atk accessibility/gnome-mag accessibility/gnome-speech accessibility/gnopernicus accessibility/gok accessibility/java-access-bridge accessibility/kdeaccessibility accessibility/kdeaccessibility4 accessibility/linux-atk accessibility/linux-f10-atk accessibility/linux-f8-atk accessibility/mousetweaks accessibility/orca accessibility/py-papi accessibility/qt4-accessible accessibility/ruby-atk accessibility/speech-dispatcher accessibility/yasr
Anybody has an idea why it hangs?

Besides I need $lb1->insert('end', "Scanning..."); to take effect before the processing starts, instead the Scanning... and Done. line appear at the same time after all is done, at least in my second code which works, but needs two sub-routines:

sub scan { $lb1->insert('end', "Scanning..."); my $counter = '0'; my $file = '/usr/ports/y.lis'; my $outf = '/usr/ports/yy.lis'; open(ARGV,$file) or die $!; open(OUTF,">$outf") or die $!; BEGIN { $/ = "\n"; $\ = "\n"; } LINE: while (defined($_ = <ARGV>)) { chomp $_; use File::Glob (); foreach $_ (glob("$_/*")) { printf OUTF "$_\n"; $counter++; } } close(ARGV); close(OUTF); print "processed $counter records."; $lb1->insert('end', "Done."); clean(); } sub clean { $portscount = '0'; $ifile = '/usr/ports/yy.lis'; $ofile = '/usr/ports/yyy.lis'; open(IFILE, $ifile) or die $!; open(OFILE,">$ofile") or die $!; while (<IFILE>) { $_ =~ s/\s+//g; if (!/Makefile(.inc|)$/) { printf OFILE "$_\n"; } else { $portscount++; } } close(IFILE); close(OFILE); print "processed $portscount records."; }
I've tried to merge (not only append!) these two sub-routines all night long without success.

Kind regards,
unknown-monk

P.S.: I wonder if it's too "noobish" to simply live with this two sub-routines.

In reply to Re^2: 2 questions about Perl/Tk and Perl by unknown-monk
in thread 2 questions about Perl/Tk and Perl by unknown-monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.