How do I read fixed-length records in Perl?

前端 未结 5 999
面向向阳花
面向向阳花 2021-01-11 13:18

What\'s the best way to read a fixed length record in Perl. I know to read a file like:

ABCDE 302
DEFGC 876

I can do

while         


        
5条回答
  •  无人及你
    2021-01-11 13:33

    Regardless of whether your records and fields are fixed-length, if the fields are separated by uniform delimiters (such as a space or comma), you can use the split function more easily than unpack.

    my ($field1, $field2) = split / /;
    

    Look up the documentation for split. There are useful variations on the argument list and on the format of the delimiter pattern.

提交回复
热议问题