How to parse a fixed length record

Discussion in 'Perl Misc' started by byrapaneni@gmail.com, Jul 30, 2005.

  1. Guest

    Hi;
    I am a new beeeee to perl. Please help me with the following.
    I have a 80 position fixed recrod that I need to parse by column for
    reporting.

    Example:
    0322095000101572000020600000200050630050630000000000000000000001108961000000016430023sf+FM+12691*206+FM110

    Field1: 1-4
    Field2: 5-8
    Field3: 9-14
    Field4:15-31
    Field5:32-34
    Field6:35-40
    Field7:41-54
    Field8:55-80

    Can somebody please help me to parse the above fixed length record?

    Thanks in advance.

    SB
    , Jul 30, 2005
    #1
    1. Advertising

  2. wrote:
    > I am a new beeeee to perl. Please help me with the following.
    > I have a 80 position fixed recrod that I need to parse by column for
    > reporting.
    >
    > Example:
    > 0322095000101572000020600000200050630050630000000000000000000001108961000000016430023sf+FM+12691*206+FM110
    >
    > Field1: 1-4
    > Field2: 5-8
    > Field3: 9-14
    > Field4:15-31
    > Field5:32-34
    > Field6:35-40
    > Field7:41-54
    > Field8:55-80
    >
    > Can somebody please help me to parse the above fixed length record?


    my @fields = unpack 'a4 a4 a6 a17 a3 a6 a14 a6', $string;

    perldoc -f pack
    perldoc -f unpack
    perldoc perlpacktut


    John
    --
    use Perl;
    program
    fulfillment
    John W. Krahn, Jul 30, 2005
    #2
    1. Advertising

  3. wrote:
    > I am a new beeeee to perl. Please help me with the following.
    > I have a 80 position fixed recrod that I need to parse by column for
    > reporting.


    Check out

    perldoc -f substr

    > Thanks in advance.


    You're welcome.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Hjalmarsson, Jul 30, 2005
    #3
  4. perlUSER Guest

    Thank you very much.
    perlUSER, Jul 30, 2005
    #4
  5. perlUSER Guest

    perldoc - f on the functions doesn't work on my server. Any ideas why?
    perlUSER, Aug 1, 2005
    #5
  6. Ian Wilson Guest

    perlUSER wrote:
    > perldoc - f on the functions doesn't work on my server. Any ideas why?
    >


    Possibly because there shouldn't be a space between the "-" and the "f"?

    In general its best to cut & paste your command + error message into
    your posting. "doesn't work" isn't very useful as a description of a
    message.

    Depending on platform/package manager/repository you may need to install
    the perl documentation separately. There was a thread on this recently,
    which google should be able to find for you.
    Ian Wilson, Aug 1, 2005
    #6
  7. * perlUSER schrieb:

    > perldoc - f on the functions doesn't work on my server. Any ideas why?

    ^^^
    Remove the space between "-" and "f". Try:

    perldoc -f substr

    Alternatively you could read all perldoc pages online, e.g. at

    http://perldoc.perl.org/functions/substr.html

    regards,
    fabian
    Fabian Pilkowski, Aug 1, 2005
    #7
  8. perlUSER Guest

    This is the command and the system response.

    ***************************************************************

    $ perldoc -f pack
    No documentation found for "perlfunc".
    $

    ***************************************************************

    >> In general its best to cut & paste your command + error message into
    >> your posting. "doesn't work" isn't very useful as a description of a
    >> message.


    Thank you for the suggestion
    perlUSER, Aug 1, 2005
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Harald Kirsch
    Replies:
    2
    Views:
    356
    Roedy Green
    Sep 4, 2003
  2. johnp
    Replies:
    4
    Views:
    3,651
    Toby Inkster
    May 23, 2005
  3. cksanjose

    Reading Fixed Length Record File

    cksanjose, Oct 27, 2006, in forum: Java
    Replies:
    3
    Views:
    649
  4. matou

    Create a record with fixed length

    matou, Nov 19, 2008, in forum: Perl Misc
    Replies:
    2
    Views:
    116
    Martien Verbruggen
    Nov 19, 2008
  5. PerlFAQ Server
    Replies:
    0
    Views:
    113
    PerlFAQ Server
    Apr 16, 2011
Loading...

Share This Page