in reply to Re: Converting Oracle report language code into perl
in thread Converting Oracle report language code into perl

This node falls below the community's minimum standard of quality and will not be displayed.

Replies are listed 'Best First'.
Re^3: Converting Oracle report language code into perl
by BrowserUk (Patriarch) on Jun 26, 2007 at 09:08 UTC

    Let's take a look at your regex:

    $def =~ s/ (^\.\w+\s) ## $1 := A '.', followed a word and a space (\w+) ## $2 := Another word (\s+) ## $3 := some whitespace (.+) ## $4 := Some anything ( ## $5 ^ ## The start of string/line select ## The word 'select' \. ## A literal '.' . ## Any single character $ ## The end of the line/string ) /$2$5/x; ## put back just first word and the 'select' etc

    Look at $5. ^ only matches the start of the string (which you already did in $1), unless you use the /m modifier.

    Same goes for $.

    Now look at the $4. '.' will not match a newline character unless you use /s. So, you will never reach the 'select' keyword, becuase your regex won't search beyond the end of the first embedded newline.

    Continuing with $5. With \..$ I think you are trying to match the '..' at the end of the string.

    First, that would need to be \.\.$

    But also, you haven't specified anything to bridge the gap between 'select' and '..', so it won't even get there.

    Maybe this will get you started, but you will have to read perlre and perlreref and try to undewrstand what is going on. If you come back asking for the next part to be solved for you without having made some progress in your own attempts, it likely will fall on deaf ears.

    #! perl use warnings; use strict; my $def = <<'EOD'; .define get_user_info select user_location,user_name, user_company, &fax_header || +';style=' || letterhead, fax_printer, nvl(fax_yn,'N') into user_location, user_name, user_company, fax_header, fa +x_printer, fax_yn from security_header where user_id = lower(substr(user,5,10)) .. EOD $def =~ s/ ( \A \. \w+ \s ) ## $1 := A '.', followed a word and a space (\w+) ## $2 := Another word (\s+) ## $3 := Some whitespace (.+?) ## $4 := Some anything ( ## $5 \s+ ## Some whitespace select ## The word 'select' [^.]+ ## Lots of anything except a '.' \. \. \Z ## Two '.'s and the end of line ) /$2$5/smx ## . matches \n; ^ & $ match lines with the string or die 'Failed to match'; print $def;

    You see those lines at the top of the code above. They are for your benefit, not the compiler's.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re^3: Converting Oracle report language code into perl
by GrandFather (Saint) on Jun 26, 2007 at 11:15 UTC

    The strong implication of your questions is that you need to write some sort of parser for a report description language that entails SQL potted inside a (presumably) light weight control language. I suggest you read the documentation for Parse::RecDescent to get a feel for what you are up against in trying to parse such a thing. A good starting point would be to find or generate a grammar for the reporting language.

    Let me reiterate: "My guess is that that could be a pretty big job."! Nibbling around the edges with a few regular expressions to try solving the problem piecemeal and coming back to us a couple of times a day to get a regex for the next piece is neither a good use of you time nor of ours.


    DWIM is Perl's answer to Gödel

      Utter rubbish! It would take 3 times as long to work out how to do this use P::RD than with regexes--and that's if you understand recursive grammar definitions, perl references and that modules bewildering documentation.

      I agree that the OP hasn't show much understanding of regexes, nor much willingness to learn, but pointing him at P::RD is just sadistic.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        Judging by the way the requirements have evolved and by OP's Re^2: Oracle report converter reply in his other relate thread, so far we have only seen the very tip of the iceberg - there is a lot more to come. Palming the OP off with a bunch of regexen solves a short term problem in a "look what I can do" fashion, but doesn't seem to be helping the OP very much at present and will lead to a maintenance nightmare for him in the longer term.

        It is hard to know what the OP's motivation for this task is, but leading him along by offering tempting morsels that will either frustrate the OP because they don't provide all of the solution, or transfer a large development project over to PerlMonks, is unlikely to get the OP to a satisfactory endpoint. In fact, that's just sadistic. Much better to be up front and say "That's a big job. Here's the tool for it." and let the OP figure out sooner rather than later that either he's not up to it, or that some serious learning needs to be done. The nice thing is that this is a pretty good place to do a lot of that learning, or at least to get a lot of guidance toward appropriate learning resources.


        DWIM is Perl's answer to Gödel
      GrandFather!! You said right .. I was going in a wrong way ..as You can understand I am not an expert perl programmer thats why I have started it that way... As u suggested I am going through the Parse-RecDescent module .... So please tell me whether I can use this for my .rpt file as well or not.. ?

        There are two things here: there seems to be no Perl tool that will provide a simple solution to your problem and, I suspect, that this task is rather beyond your current programming abilities. While we can provide various suggestions and even substantial code, at the end of the day you have to be able to assimilate that information and use it to complete your task.

        There are many ways to solve your problem. The regular expression based approaches offered so far are appropriate for the the fairly straight forward parsing/extraction problem you have presented and in fact if that is the exetent of your task then it has already been solved for you. I suspect though that the problem as expressed is actually a small part of a larger project that may be better tackled with heavier duty tools, which is why I mentioned Parse::RecDescent. However more powerful tools generally require more work to understand and use.

        If you provide us with the larger picture we may be able to suggest an alternative way of tacking the bigger issue rather generating more frustration for everyone by trying to solve parts of it piecemeal and out of context.


        DWIM is Perl's answer to Gödel
        A reply falls below the community's threshold of quality. You may see it by logging in.