Two questions today from another valiant but ignorant novice --- with thanks in advance!

1 Given the following code, how do I use Perl's flock function to exclusively lock "file" (comprised of a list of fund tickers) so that, while subroutine "process" reads from "file" and executes, the user can't mangle "file" via subroutine "alter_file"?

2 Should "process" hang for some unknown reason, how can the user terminate whatever processs(es) UserAgent "$html_source" is executing? (Exact SIG code much appreciated.)

use Tk; use LWP::Simple; use LWP::UserAgent; use FileHandle; $mw = MainWindow -> new;what $screw = $mw -> Button ( -text => "screw up ticker file", -command => [ \&alter_file ] ) -> pack; $go = $mw -> Button ( -text => "go", -command => [ \&process ] ) -> pack; $stop = $mw -> Button ( -text > "stop", -command => [ \&stop_process ] ) -> pack; $html_source = new LWP::UserAgent; MainLoop; sub alter_file { open ( HANDLE1, "+< file" ); # OPEN FOR READ/WRITE while ( <HANDLE1> ) { chop; chop; chop; # SCREW UP file } close HANDLE1; } sub process { open ( HANDLE2, "< file" ); # OPEN FOR READ-ONLY # WANT TO LOCK HANDLE2 SO THAT USER CAN'T SCREW UP file WHILE # THE FOLLOWING CODE EXECUTES while ( <HANDLE2> ) { $html_source -> get ( "http://quicktake.morningstar.com/ FundNet/Snapshot.aspx?Symbol=$_" ); # DO WHATEVER WITH $html_source CONTENT } close HANDLE2; } sub stop_process { # WANT TO SIGNAL USERAGENT $html_source TO STOP (OR DESTROY?) # ITSELF # (AS A SIDE QUESTION: ASSUMING IT'S STILL OPEN, HOW WOULD I # THEN CLOSE HANDLE2?) }

In reply to Two questions on interprocess communication by cypress

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.