perl program?

May 31, 2011 – 2:59 am

Code:
open (NGC_Input_File,"ngc_update.xml");

Problem:
I’m new in perl and i have a code above. but i wanted to add where it will pick up any file that starts with ngc (ngc*.xml). I tris experimenting by adding * and othre stuff but it wont work plase help??

Also is it possible to add a directory. Let say C:\perl\bin in the code? if so how?

Related posts:

  1. perl program?
  2. how can I make a program launch another program using perl?
  3. Learning to program in Perl?
  4. how do I find the path to perl from with in a perl program?
  5. Using $ARGV[1] in PERL to open any text file for this program.?
  6. Can't run perl program.?
  7. perl program???
  8. In PERL how do you open different text files with the same program?
  9. How can I make a simple Perl program work?
  10. How do you get the source code of a program? PERL?
  1. 2 Responses to “perl program?”

  2. Here’s an approach:
    If you need to open one file at a time, you could glob all the required files in one shot such as:

    @files = glob("ngc*.xml");

    OR

    opendir(DIR, $path);
    @files = grep { /^ngc*\.xml$/ } readdir(DIR);
    closedir(DIR);

    and then you would use a foreach loop to open individual files:

    foreach $file (@files) {
    process($file);
    }

    I have not compiled or tested the code above. But you get the idea.

    By Howdy on May 31, 2011

  3. Im off to sleep myself, but just for future answerers, please specify what you mean by adding a dircetory, since at least i didnt really figure out what you were meaning with that.

    But if you meant if you can open for example a file from C:somethhing/something, then yes, it is possible. and not sure, but i think you had the right kind of way on taht example, but could be different for that beginning C:.

    Also notice that theres chance that your perl program might not be able to do that right away and might require something like "file:C:" if its aimed for webpage programming only.

    Or it might require you to start it from "Command" for it to right way go finmd the C:, and especially if you are running that program from a website, then if you use C:. it wil lrefer to that servcers C: harddisk, and you shouldnt have right to access that.

    So in case trying to acces your harddisk thorugh wewbpage, i guess it would be something like "local://C:/something/something.stg"

    But i trust better guys answer more accurate, i dont eeally remember any of these right waway, so mostly just guessing.

    By Bugala on May 31, 2011

Sorry, comments for this entry are closed at this time.