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

I need to parse info from a file and example is given below:

a b c d e f

I need to grab all lines from a to c (the double-return) and parse it to a file.

2002-03-13 Edit by Corion : Added CODE tags to reveal formatting

Replies are listed 'Best First'.
Re: Parsing Info
by rnahi (Curate) on Mar 13, 2002 at 17:54 UTC
    I am not sure about your input (you should use the <code> tags). But if you mean something like this, then it's easy.
    The "$/" variable holds the separator. Changing it to a double return, will parse what you want.
    #!/usr/bin/perl -w use strict; my @array =(); { local $/="\n\n"; push @array, $_ while <DATA> } print join (",", split( /\n/, $_)),"\n" for (@array) ; __DATA__ a b c d e f
    Each "record" in the array is a group of three lines, which you can then separate using the split function.
Re: Parsing Info
by PrimeLord (Pilgrim) on Mar 13, 2002 at 17:28 UTC
    You aren't giving us very much to go on. Next time you may want to go a little more into detail as to what exactly you are trying to do. And it is best to give some example code of what you have already tried. With that being said reading open, split, and perlfaq6 will probably get you started.

    Update: You should also consider reading Before You Post... for some guidelines on asking for help.
      Whats up with the down votes I am getting for this post? There was no code or a clear direction given by the author of the node so I directed the author towards a possible good place to start as oppsoed to doing their work for them. I don't see the problem with that.

      -Prime
Re: Parsing Info
by silent11 (Vicar) on Mar 13, 2002 at 17:32 UTC
    If I understand correctly you want to parse a file that looks like this:
    a b c d e f
    Depending on the size of the file I would read it all into a string and slit on /^\n/.
    open(FILE,"<some.file"); $string = <FILE>; @array = split(/^\n/,$string); # split where the \n is the first thing + on that line. # then do stuff with each element in @array.

    -Silent11