Is there a one-liner to get the first element of a split?

前端 未结 3 412
梦如初夏
梦如初夏 2021-01-01 09:54

Instead of writing:

@holder = split /\\./,\"hello.world\"; 
print @holder[0];

is it possible to just do a one-liner to just get the first e

3条回答
  •  暖寄归人
    2021-01-01 10:16

    I get the following error when I try the second example: "syntax error at test.pl line 3, near ")["

    No, if you have warnings enabled as you should, you get:

    print (...) interpreted as function at test.pl line 3.
    syntax error at test.pl line 3, near ")["
    

    which should be a big clue as to your problem.

提交回复
热议问题