Perl assignment with a dummy placeholder

后端 未结 4 2254
北恋
北恋 2020-12-18 17:51

In other languages I\'ve used like Erlang and Python, if I am splitting a string and don\'t care about one of the fields, I can use an underscore placeholder. I tried this

4条回答
  •  情深已故
    2020-12-18 18:39

    You don't even need placeholders if you use Slices:

    use warnings;
    use strict;
    
    my ($id) = (split /=/, 'foo=id123')[1];
    print "$id\n";
    
    __END__
    
    id123
    

提交回复
热议问题