skyler has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: File Parsing and String Formatting
by l2kashe (Deacon) on Feb 17, 2003 at 02:42 UTC
    When posting a question please take the time to make sure it says what it should, and that the data examples show up like you excpect them to. Its a little tough to grok what the actual string you are working with is, but I'll give it a shot

    # lets assume we are starting after the split in your sub # so the contents of @fields would be @fields = ( '463694', 'BROOKS JR', 'JAMES', 'ArnoldMarkoe', '1/17/03', 'MD Wkly Note', '17\00004DA5.005' ); # # So with that assumption you are attempting to join 0 .. 5 # and the last field's file extension? # here im not sure if you want the actual file name, or # simply the extension of the file, as you are going to # glob all files in that sub dir with that file extension # I will assume its the last case. # $line = join('|', @fields[0 .. 5]) . '|H:\\' . ( split(/\\/, $fields[-1]) )[0] . '\\.' . ( split(/\./, $fields[-1]) )[1]; print "$line\n"; # # which will produce # 463694|BROOKS JR|JAMES|ArnoldMarkoe|1/17/03|MD Wkly Note|H:\17\.005

    Im not sure if that is what you actually want or not. If you could refine the exact data you are trying to get, it might make it easier to help you.

    BTW, what I am doing with the splits is working with the last element of fields ( ala $fields-1 ), and split returns an array of elements that were successfully split. So I take the entire split expression, slap it in parenthases, and treat it like a normal array slice, and only return the elements I want. In the first case, I split on \, and return elem 0 which should be the sub dir if Im reading your data correctly. In the second case I split on . and return the second element, which should be the file extension. I am assuming that there is only one . in the string, which may be false, but I cant tell without more data.



    /* And the Creator, against his better judgement, wrote man.c */
      I'll appreciate you getting back. what I was trying to format is to get the data to send a result like:
      463694|BROOKS JR|JAMES|ArnoldMarkoe, 1/17/03|MD Wkly Note|H:\17\00004DA5.005
      I'm reading a file and outputing it to another file. unfortunately it is giving me this result: 464734|CARRASO|ZONIA|Cristiane Takita|12/18/02|MD Wkly Note|H:\08\00004DC4.0138\\00004DC4.013| do you think, I should put me code any other way?? my $out = join '|', @fields[0..5], $finstring,"\n";
        It appears from your output, that you are appending the same data to the $finstring scalar twice.

        Look at your last item in your output
        H:\08\00004DC4.0138\\00004DC4.013
        the bold italicized text is a duplicate of what comes before it. You are getting the data you want, you simply need to find in your code where you are getting the same data, and drop that portion.


        /* And the Creator, against his better judgement, wrote man.c */
Re: File Parsing and String Formatting
by tachyon (Chancellor) on Feb 17, 2003 at 02:51 UTC