Professional Web Applications Themes

Reading a variable file name - PERL Beginners

Greetings, Would someone be kind enough to point me in the right direction to solve this problem? An application creates XML files in a subdirectory, which I then convert to EDI. That part is now working fine. My problem is that the application creates files during the day, with slightly different names. For example: File0001.xml File0002.xml File0244.xml The file names vary based on what part of the application creates them. There seems to be no pattern of the number after the alpha characters. I need to read each of these files, and concatenate them into a single EDI file. The ...

  1. #1

    Default Reading a variable file name

    Greetings,

    Would someone be kind enough to point me in the right direction to solve this
    problem?

    An application creates XML files in a subdirectory, which I then convert to
    EDI. That part is now working fine. My problem is that the application
    creates files during the day, with slightly different names. For example:

    File0001.xml
    File0002.xml
    File0244.xml

    The file names vary based on what part of the application creates them.
    There seems to be no pattern of the number after the alpha characters. I need to
    read each of these files, and concatenate them into a single EDI file. The
    only files in the subdirectory need to be processed; and all of the files in
    the subdirectory need to be processed.

    Could someone point me in the right direction?

    Thanks for your help.

    Richard Hug
    New Tampa Consulting
    813-361-7946

    RHug505456@aol.com Guest

  2. #2

    Default Re: Reading a variable file name

    On Jul 13, 2004, at 8:31 AM, com wrote:
     

    Howdy.
     

    I'll sure try.
     

    We can sure make a regex for that, right?

    m/^File\d+\.xml$/
     

    Do you know how to read the listing of files in a directory? Three
    steps:

    opendir DIR, 'path/to/dir' or die "Directory error: $!"; # open dir

    my files = grep m/^File\d+\.xml$/, readdir DIR; # get file listing
    using earlier regex

    closedir DIR; # clean up after ourselves, as all good programmers
    should

    # loop over files down here...
     

    Was that line English? <laughs> You lost me here. If I haven't
    solved your problem yet, try me again on this part.
     

    Hope that helps.

    James

    James Guest

  3. #3

    Default Re: Reading a variable file name



    com wrote:
     

    Hello,
     

    I'll try :)
     

    Not sure about how the filename effects if you want to incude it or not
    but:

    #!/usr/bin/perl

    use strict;
    use warnings;
    use File::Slurp;

    for(read_dir('/xml/files')) {
    if($_ =~ m/\.xml$/) {
    my $xml = read_file("/xml/files/$_");
    append_file('/xml/together.edi',$xml);
    }
    }
     

    No problem :)

    Lee.M - JupiterHost.Net
    Jupiterhost.Net Guest

  4. #4

    Default Re: Reading a variable file name

    com wrote:
     

    Hello,
     

    Ok, but please post to the list so everyone can share :)
     

    Yes,
    perl -MCPAN -e 'install File::Slurp;'
    shoudl do it
     

    It is a subroutine, exported by File::Slurp; which you need to install
     

    Correct same as #2
     

    No problem! If you want to show your appreciation you could always
    signup for hosting at JupiterHost.Net and tell your friends - tell them
    Lee sent you :)
     

    HTH :)

    Lee.M - JupiterHost.Net
    Jupiterhost.Net Guest

Similar Threads

  1. Reading Environment Variable
    By Les T in forum Coldfusion - Advanced Techniques
    Replies: 0
    Last Post: June 3rd, 11:15 PM
  2. Reading a variable from a web page ?
    By craig_uk in forum Macromedia ColdFusion
    Replies: 1
    Last Post: April 8th, 07:21 PM
  3. Reading dynamic FORM variable value
    By ldonner in forum Coldfusion - Advanced Techniques
    Replies: 1
    Last Post: April 4th, 02:39 AM
  4. Replies: 0
    Last Post: September 2nd, 11:38 AM
  5. Session variable reading doesn't work
    By Peter in forum PHP Development
    Replies: 5
    Last Post: July 29th, 09:32 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139