这条线在Perl中有什么作用?

时间:2017-10-20 18:24:19

标签: perl

这一行在Perl中做了什么?

s/\s//g;

我正在查看用于搜索和计算输入文件中某些字符的脚本,除了这一行,我理解代码中的所有内容。我想知道这条线为剧本做了什么?

1 个答案:

答案 0 :(得分:2)

#include <stdio.h>
#include <stdlib.h>
#include <cs50.h>
#include <math.h>
#include <string.h>
int main(void)
{
  long long ccn = get_long_long("Enter CCN: \n");
  int count = 0;
  long long ccn1 = ccn;
  // finds the amount of digits entered and stores that in int count.
  while (ccn1 != 0)
  {
     ccn1 /= 10;
     +count;
  }
  printf("%i \n", count);
  // ln 17- 19 should take int count, subtract two, put that # as the power of 10, 
  // then divide the CC# by that number to get the first two numbers of the CC#.
  long long power = count - 2;
  // here is where i get the error. its a long long so it 
  // should hold up to 19 digits and im only storing 14 max 
  // but it says that 10^14th is too large for type 'int'
  long long divide = pow(10,power);
  long long ft = ccn / divide;
  printf("power: %i \n", power); //ln 20-22 prints the above ints for debug
  printf("Divide: %lli \n", divide);
  printf("First two: %lli \n", ft);
  string CCC;
  // ln 24-35 cross references the amount of digits in the CC#
  // and the first two digits to find the comapany of the credit card
  if ((count == 15) && (ft =  34|37))
  {
    CCC = "American Express";
  }
  else if ((count == 16) && (ft = 51|52|53|54|55))
  {
    CCC = "MasterCard";
  }
  else if ((count = 13|16) && (ft <=49 && ft >= 40))
  {
      CCC = "Visa";
  }
  printf("Company: %s\n", CCC);
}

的缩写
s/\s//g;

$_ =~ s/\s//g; $_绑定。它会替换$_中与substitution operator \s匹配的所有序列。 (没有g,它只会替换第一个。)

\s匹配空白字符。