Skipping fields when using unpack()

Discussion in 'Perl Misc' started by John Ramsden, Aug 15, 2003.

  1. John Ramsden

    John Ramsden Guest

    I need to extract a couple of ASCII fields from a string of fixed-length
    fields, let's say 'ABCxPQxxUVW' in which I'm not interested in characters
    in positions indicated by 'x'. This can easily be done by the code line:

    ($a, $junk1, $p, $junk2, $u) = unpack "A3 A A2 A2 A3", $string;

    But I was wondering if there is an unpack() spec one could use in the
    control string to skip the junk fields and not have to extract them,
    thus making the code slightly shorter.

    I have tried reading the unpack and pack perldoc schpiel, but can't see
    any obvious solution.


    Cheers

    John R Ramsden ()
    John Ramsden, Aug 15, 2003
    #1
    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. Pieter Rautenbach

    Type discrepancy using struct.unpack

    Pieter Rautenbach, Oct 19, 2006, in forum: Python
    Replies:
    2
    Views:
    317
    Pieter Rautenbach
    Oct 19, 2006
  2. Tim Chmielewski

    Skipping fields in a request object?

    Tim Chmielewski, Jun 10, 2004, in forum: ASP General
    Replies:
    0
    Views:
    101
    Tim Chmielewski
    Jun 10, 2004
  3. Greg Hurrell

    Using unpack on a UTF-8 string

    Greg Hurrell, Feb 24, 2007, in forum: Ruby
    Replies:
    3
    Views:
    255
    Clifford Heath
    Feb 25, 2007
  4. pip

    Extraction of bits using unpack

    pip, Aug 17, 2005, in forum: Perl Misc
    Replies:
    2
    Views:
    105
  5. Peter Cacioppi
    Replies:
    21
    Views:
    182
    Neil Cerutti
    Oct 21, 2013
Loading...

Share This Page