How do I read fixed-length records in Perl?

前端 未结 5 865
面向向阳花
面向向阳花 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:34

    Here's yet another way to do it:

    while ()
    {
        chomp;
        if (/^([A-Z]{5}) ([0-9]{3})$/)
        {
            $key = $1;
            $value = $2;
        }
    }
    

提交回复
热议问题