Regex: How to remove extra spaces between strings in Perl

前端 未结 5 499
不知归路
不知归路 2021-01-18 10:03

I am working on a program that take user input for two file names. Unfortunately, the program can easily break if the user does not follow the specified format of the input.

5条回答
  •  终归单人心
    2021-01-18 10:41

    While I think your design is a little iffy, the following will work?

    my @fileNames = split(',', $filenames);
    foreach my $fileName (@fileNames) {
      if($fileName =~ /\s/) {
        print STDERR "Invalid filename.";
        exit -1;
      }
    }
    my ($qsec, $barcode) = @fileNames;
    

提交回复
热议问题