-1

I have a text file which contains the following data:

ChainCtrlBuildChain() : ChainController.c
ChainCtrlDumpChain() : ChainController.c
ChainCtrlDumpChanCallback() : ChainController.c
ChainCtrlExit() : ChainController.c
ChainCtrlGetBitStreamChan() : ChainController.c
ChainCtrlInit() : ChainController.c

I want to copy only the function names into another text file.

My desired output:

ChainCtrlBuildChain
ChainCtrlDumpChain
ChainCtrlDumpChanCallback
ChainCtrlExit
ChainCtrlGetBitStreamChan
ChainCtrlInit

How can I do it?

Note that the function names and class names will be different depending on user input.


By using user4035's code,

$text =~ s/\s:\s.*//g;

I got "()" outside function body like

ChainCtrlBuildChain()
ChainCtrlDumpChain()    
4

1 回答 1

1

我只会给你文本处理部分。我认为,您可以自己进行文件 I/O。

#!/usr/bin/perl

use strict;
use warnings;

my $text = qq{ChainCtrlBuildChain() : ChainController.c
ChainCtrlDumpChain() : ChainController.c
ChainCtrlDumpChanCallback() : ChainController.c
ChainCtrlExit() : ChainController.c
ChainCtrlGetBitStreamChan() : ChainController.c
ChainCtrlInit() : ChainController.c};

$text =~ s/\s:\s.*//g;
print $text;

印刷:

ChainCtrlBuildChain()
ChainCtrlDumpChain()
ChainCtrlDumpChanCallback()
ChainCtrlExit()
ChainCtrlGetBitStreamChan()
ChainCtrlInit()
于 2013-07-30T08:02:12.697 回答