Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Honored monks:

I use Perl under WinXP and Mac OS X, but this question is specifically for WinXP (although I may want to port the script to Mac somedayP.

This script, index.pl, opens the current directory with the filehandle POSTED and looks for filenames beginning with a certain pattern, (/^(\d{6}[b-z]?) /). It analyzes each such filename with a series of regexps, then writes the results of its analysis for each filename to an output file (handle OUT) as tab-delimited text.

When it's done all such files -- when the while(($file = readdir(POSTED))) {...} loop is done -- it closes OUT and calls system to open it in NotePad.

Then I manually "select all" in NotePad, "copy", and close the file. The script then opens an Excel spreadsheet into which I paste the data for further manipulation. Here's the main code:

open(OUT, '>', 'index.txt') or die($!); &byfile; # subroutine to find, analyze, & write filenames printf STDERR ("%d lines processed\nwith header, " . "%d lines written to index.txt", $lines, $lines + 1); close(OUT); system("notepad index.txt"); system("index.xlsx");

Here's the problem: I often run this script iteratively to make sure that new files are getting treated properly, or when tweaking the program. At such times, I already have the spreadsheet open from the previous iteration. The script works all right, but I keep getting error messages on the terminal window: "The process cannot access the file because it is being used by another process." Not only is this a nuisance, but the script has wasted time (I don't know if any significant amount) in vainly trying to open a file that's already open.

My question, then: How can I test whether the spreadsheet is already "being used by another program" (namely, Excel)? I can't do a filehandle test because I didn't open it in Perl.

Respectfully awaiting enlightenment,
Your humble student Thnidu


In reply to is this file open? by thnidu

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!
  • 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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others romping around the Monastery: (19)
    As of 2015-07-29 15:06 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (263 votes), past polls