I am taking some basic data from a text file and am trying to get ride of a few things in each string of data. Since I am very new to perl programing, I don't have a clue of how to do it.
Here is the sample script of what I am trying to do. It has some sample data in it as $stringX.
#!/usr/bin/perl -w
$string1="# include $RULE_PATH/chat.rules";
$string2="include $RULE_PATH/chat.rules";
$string3="#include $RULE_PATH/chat.rules";
$string4="#include chat.rules";
print "\n\n\nOrginal Strings\n";
print "$string1\n";
print "$string2\n";
print "$string3\n";
print "$string4\n";
($strmod1) = $string1 =~ /[#]*(\S+)\.rules/;
($strmod2) = $string2 =~ /[#]*(\S+)\.rules/;
($strmod3) = $string3 =~ /[#]*(\S+)\.rules/;
($strmod4) = $string4 =~ /[#]*(\S+)\.rules/;
print "\n\n\nNew Strings\n";
print "$strmod1\n";
print "$strmod2\n";
print "$strmod3\n";
print "$strmod4\n";
print "\n\n\n";
As you can see the stringX var's have a $ in them. First, I want the script to ignore the $ and to just treat the string as a string. Right now I am getting a:
Use of uninitialized value in concatenation (.) or string at ./ruletest.pl line 3.
Use of uninitialized value in concatenation (.) or string at ./ruletest.pl line 4.
Use of uninitialized value in concatenation (.) or string at ./ruletest.pl line 5.
Second, the only thing that I want to have in the strmod's is the word chat and nothing else. So the output should just be "chat".
Each string is an example of the type of data that I will be gathering.
Any ideas?
Here is the sample script of what I am trying to do. It has some sample data in it as $stringX.
#!/usr/bin/perl -w
$string1="# include $RULE_PATH/chat.rules";
$string2="include $RULE_PATH/chat.rules";
$string3="#include $RULE_PATH/chat.rules";
$string4="#include chat.rules";
print "\n\n\nOrginal Strings\n";
print "$string1\n";
print "$string2\n";
print "$string3\n";
print "$string4\n";
($strmod1) = $string1 =~ /[#]*(\S+)\.rules/;
($strmod2) = $string2 =~ /[#]*(\S+)\.rules/;
($strmod3) = $string3 =~ /[#]*(\S+)\.rules/;
($strmod4) = $string4 =~ /[#]*(\S+)\.rules/;
print "\n\n\nNew Strings\n";
print "$strmod1\n";
print "$strmod2\n";
print "$strmod3\n";
print "$strmod4\n";
print "\n\n\n";
As you can see the stringX var's have a $ in them. First, I want the script to ignore the $ and to just treat the string as a string. Right now I am getting a:
Use of uninitialized value in concatenation (.) or string at ./ruletest.pl line 3.
Use of uninitialized value in concatenation (.) or string at ./ruletest.pl line 4.
Use of uninitialized value in concatenation (.) or string at ./ruletest.pl line 5.
Second, the only thing that I want to have in the strmod's is the word chat and nothing else. So the output should just be "chat".
Each string is an example of the type of data that I will be gathering.
Any ideas?