-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()    
Community
  • 1
  • 1
Ad-vic
  • 519
  • 4
  • 18

1 Answers1

1

I'll give you only text processing part. I think, you can do the file I/O yourself.

#!/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;

Prints:

ChainCtrlBuildChain()
ChainCtrlDumpChain()
ChainCtrlDumpChanCallback()
ChainCtrlExit()
ChainCtrlGetBitStreamChan()
ChainCtrlInit()
user4035
  • 22,508
  • 11
  • 59
  • 94
  • It works. Thanks.I did the I/O myself. I am new to perl so i didn't understand this line "$text =~ s/\s:\s.*//g;". But i will google it and try to figure it out. – Ad-vic Jul 30 '13 at 09:10
  • @user2628315 Search for regular expressions tutorial in Perl. This line replaces [space][:][space][anything up to the end of line] to and empty string – user4035 Jul 30 '13 at 09:21