in reply to Writing a parser

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

Replies are listed 'Best First'.
Re^2: Writing a parser
by moritz (Cardinal) on Jan 29, 2008 at 21:08 UTC
    I think we don't understand each other.

    I can second that.

    Perlmonks is good when you want to learn something about Perl, or have a problem that you can't solve on your own. It's certainly not a "we write code according to your specs, for free" site. (There are some freelancers here who will work for you if you pay them, though).

    So if you want help, show some effort on your own, show us what you've got so far, and where your problems are - then you'll get help. For sure.

    And be sure to specify the exact problem - do you need to parse the whole file? or just the first line?

      I want to parse whole file, but it isn't important, what parser it has to be. I only want to know, how to make Perl script know that his task is to parse file due to fact that the file ran parser thanks to headline. Such script as I showed would be the simpliest way to see the parser layout.
Re^2: Writing a parser
by GrandFather (Saint) on Jan 29, 2008 at 21:30 UTC

    I think you have hit a language barrier. Not a programming language barrier, but an English usage one! You may find it helpful to find someone who is more comfortable with English and can better translate your intent for you. Alternatively, post a native language version of your question and with luck another monk who understands your native language may be able to either answer your question, or at least provide a translation that better conveys your intent into English.

    Or, as another alternative, extend your example with a small real example of the input to, and expected output from the script you are having trouble with.


    Perl is environmentally friendly - it saves trees
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re^2: Writing a parser
by dwm042 (Priest) on Jan 29, 2008 at 20:57 UTC
    Zielony, I don't think you're asking a perl question, it's a Unix question you're asking. If a text file is an executable, and the first line is:

    #!something_here
    Then if an executable is in the command path named something_here, then something_here is used to run the file. Something_here can be any kind of executable, including a parsing perl script.

      Actually I just tried that and it won't work for me unless it's a true executable. If I try to use a perl script it actually gets passed to bash for some reason.

      Unless I'm doing something wrong of course...

      [root@spoonbill root]$ cat /sbin/parser #!/usr/bin/perl while (<>) { print "line: $_"; } [root@spoonbill root]$ cat scr #!/sbin/parser this is my file

      This works:

      [root@spoonbill root]$ /sbin/parser scr line: #!/sbin/parser line: this line: is line: my line: file line:

      This does not:

      [root@spoonbill root]$ ./scr ./scr: line 2: this: command not found ./scr: line 3: is: command not found ./scr: line 4: my: command not found Usage: file [-bciknsvzL] [-f namefile] [-m magicfiles] file... Usage: file -C [-m magic]

      (All run as root just in case there was a permission problem)

        I'm sorry to tell you, but on Linux, that is not allowed. On * nix systems the exec family of calls is used to start processes. From the execve(2) man page:

        execve() executes the program pointed to by filename. filename must be either a binary executable, or a script starting with a line of the form "#! interpreter [arg]". In the latter case, the interpreter must be a valid pathname for an executable which is not itself a script, which will be invoked as interpreter [arg] filename

        Note where it says, "the interpreter...is not itself a script". So you will have to use
        #!/usr/bin/perl /path/to/my/script

        --traveler
        Yeah, here is the problem. I was trying exactly as you.
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re^2: Writing a parser
by apl (Monsignor) on Jan 29, 2008 at 21:30 UTC
    Write for me parser

    Certainly. How much are you offerring for the project? Or do you want us to bid on the task?