Perl - get first “word” from input string

后端 未结 2 485
广开言路
广开言路 2021-01-11 15:44

I am trying to write a Perl program that reads in lines from a text file, and, for each line, extract the first \"word\" from the line, and perform a different action based

2条回答
  •  [愿得一人]
    2021-01-11 16:09

    This will cover all of your cases and then some:

    my ($key, $value) = split /\s*:\s*/, $inputline, 2;
    

    (Or, in English, split $inputline into a maximum of two elements separated by any amount of whitespace, a colon and any amount of whitespace.)

提交回复
热议问题