in reply to Re: 2 questions about Perl/Tk and Perl
in thread 2 questions about Perl/Tk and Perl

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.