小编Ad-*_*vic的帖子

使用用户输入名称重命名文件

我想将我的临时文件"file3.c"重命名为用户输入文件名.从File :: copy使用重命名或移动命令不会重命名它.

use strict;
use warnings;
use File::Copy;

#input header file
print "Input file1:\n";
$input = <>;
open(FILE1, $input) || die "couldn't open the file!";

open(FILE3, '>>file3.c') || die "couldn't open the file!";
...
#some work on file3.c
...

close(FILE1); 
close(FILE3);

#renaming prepended temporary file name to original file name
rename("file3.c", "$input");
Run Code Online (Sandbox Code Playgroud)

OUTPUT没有重命名

我该如何重命名?

perl perl-module

1
推荐指数
1
解决办法
128
查看次数

如何删除重复的#include指令?

#include <stdint.h>
#include <stdlib.h>
#include <VideoInChain.h>
#include <VideoOutChain.h>
#include <stdint.h>
#include <stdlib.h>
...//rest of code
Run Code Online (Sandbox Code Playgroud)

有系统头文件重复我需要删除而不影响其余的代码

我试过了

sub uniq {
  my %seen = ();
  my @r = ();
  foreach my $a (@_) {
     unless ($seen{$a}) {           
         push @r, $a;
         $seen{$a} = 1;
      }
    }
  return @r;
  }
  @lines_temp = uniq(@lines_temp);
Run Code Online (Sandbox Code Playgroud)

但它删除了所有类型的重复,包括'(','{'和空格

我只需要删除重复的系统文件

perl hash

0
推荐指数
1
解决办法
83
查看次数

使用#ifdef宏不起作用

我正在使用MACRO来定义变量SUCESS

#ifdef SUCCESS
    #undef SUCCESS
    #define SUCCESS  0
#endif //SUCCESS
Run Code Online (Sandbox Code Playgroud)

但Eclipse编译器给出了我的错误

symbol "SUCCESS" could not be resolved
Run Code Online (Sandbox Code Playgroud)

但如果我写的话

#define SUCCESS  0
Run Code Online (Sandbox Code Playgroud)

它工作正常.为什么会如此.我只能用#ifdef写

c c++

0
推荐指数
1
解决办法
703
查看次数

我如何使用Perl :: Critic :: Policy :: ValuesAndExpressions :: ProhibitMagicNumbers

我想使用模块Perl :: Critic :: Policy :: ValuesAndExpressions :: ProhibitMagicNumbers来检查.C文件中的幻数

use strict;
use warnings;
use Perl::Critic;

open(my $FILE, "< test.c") or die $!;
my $critic = Perl::Critic->new(); 
my @violations = $critic->critique($FILE);
print @violations;

close($FILE);
Run Code Online (Sandbox Code Playgroud)

如果我使用Perl :: Critic,我得到错误无法解析代码:解析Perl文档时出现未知错误

如果我使用Perl :: Critic :: Policy :: ValuesAndExpressions :: ProhibitMagicNumbers,我得到错误无法通过包"Perl :: Critic"找到对象方法"new"

perl perl-module

-1
推荐指数
1
解决办法
93
查看次数

标签 统计

perl ×3

perl-module ×2

c ×1

c++ ×1

hash ×1