<snip> > >> movie listing and when one item is selected via remote, 'system' > >> invokes mplayer which leaves main gtk window blank after it finishes? > >> :) > > > >Perl 5.6.x is not threaded, so anything that blocks (like system) will > >keep the gui from updating. To launch another app you should fork and > >then exec the other app without waiting your the child to die. > > > I guess another way is to somehow force gui updating? </snip>
You are blocked (waiting for the system call to return) therefore no code is being executed in your script (hence no updating of gui). Avoiding blocking calls is not as important when you are using C since Gtk/Gnome in C is threaded, but Perl prior to version 5.8 does not have a good threading model so Gtk/Gnome is not threaded. What does this mean? It means from the time you enter a callback function to the time the function returns _no_ updates are occurring for the GUI. You can fix this by manually processing Gdk events if your callback function is not blocking (ie opening a DB connection, issuing a system call, or any other outside function that takes time to return control to your code). If your code does have a blocking problem you will have to work around this somehow (worst case scenario: write a module in XS or Inline::C to handle this callback). Here is an example of some code from one of my projects (http://sourceforge.net/projects/gsqleditor/). <example> $stat->set_status('Fetching...'); my $i = 0; while (my $ref = $sth->fetch) { last if $stop; push @d, $ref; $stat->set_status("Fetching $i..."); $i++; Gtk->main_iteration while (Gtk->events_pending); } </example> This snippet comes from the callback that handles the pressing of the run button. $sth holds a DBI statement handle for the current query and the fetch method returns the next row from the result set. $stat is the status bar for this application. $stop is an 'our' variable that is set to 1 at the end of this function or whenever the stop button is pressed. @d is an array tied to Gtk::CListModel (adding an array ref to the @d adds it to the CList). The rest of the variables are self explanatory. What is happening here is I am fetching all of the rows from my select statement and shoving them into a CList. When I first wrote this code I didn't think about the fact that Perl isn't threaded and just naively wrote a loop to shove the rows into the CList. <example> while (my $ref = $sth->fetch) { $list->freeze; no warnings; $list->append(@$ref); use warnings; $list->thaw; } </example> I was not very satisfied with the resulting performance. The app basically froze whenever I ran a query. After much research I eventually realized that this was because Perl is not threaded and I wasn't handing control back to the main loop until the end of the callback (sometimes this took hours since I was running multiple sql statements). The solution was to hand control back to the main loop with the Gtk->main_iteration function. Now, at that point I had to make a decision: which is more important the app or shoving rows into the CList. If the app is more important then you will want to do what I did in the first example (process all outstanding events every time through the loop). If shoving data into the CList is more important then you will want to call Gtk->main_iteration less frequently (or not at all if you don't mind the app not refreshing). <snip> > >> ---------------------------------------------------------------------- > >> Is there a way to use 'format' where I could write to scalars instead > >> to file handles?(usefull when cgi sends mail and shows same content in > >> the browser) > > > >I assume you are referring to the write function and formats. I believe > > yes. > > >there is a way to get at the Perl variables used to do the formating, > >but that is ugly (see perldoc perlvar for more info). Is there a reason > >you are not using sprintf (see perldoc -f sprintf)? > > Actually there isn't a strong reason for format, I just thought the > code would look more cleanly. </snip> Format/write is nice for small scripts, but (in my experience, maybe somebody else on this list will be able to help you) it generally loses readability as a project grows. <wild tangent>Perhaps it would be a good idea to wrap format up in OO clothes and attach it to IO::File. I think this close to what they are doing with Perl 6. I need to look on CPAN now.</wild tangent> <snip> > > >> ---------------------------------------------------------------------- > >> How to match complex repeating patterns, i.e. I want to match > >> (\d{6}.*?\t) ten times and read values of the last three? </snip> <snip> > Tnx, I was using split but thought that single regex would be more > optimized and shorter for this kind of task. :) </snip I almost asked why you weren't using split. I assumed that there was data between your regex hits. Since this isn't the case I would recommend using something like: <example> #Split $string on tabs up to ten times and take the last #three elements my @I_care_about_these = (split /\t/, $string, 10)[-3,-2,-1]; #Only necessary if $string can have more than ten items #in it, otherwise the last element will have the rest of #the unsplit string in it. If you know there will always #be more than ten lines you can say #my @I_care_about_these = (split /\t/, $string, 11)[7,8,9]; #instead and skip this. $I_care_about_these[-1] =~ s/\t.*//; </example> -- Today is Pungenday the 47th day of Confusion in the YOLD 3168 Missile Address: 33:48:3.521N 84:23:34.786W -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]