Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with pattern matching

Status
Not open for further replies.

rogermills

IS-IT--Management
Oct 27, 2009
1
US
Hi
I am new to perl so bear with me. I am writing a subversion hook script in perl. The script will check the log message at commit and get the issue ID (e.g. CNR12345) from the message, if the issue ID is not found in the log message it will block the commit else move on. The problem is it will reject the commit if it cannot find a Issue ID which works as expected. But when there is a Issue present still it is reject the commit. It should not reject the commit if the issue is there. The issue ID is like CNR12345 and start's at the beginning of the log message.

Thanks guys

Roger

Code:
 #!D:\perl\bin\perl
 use strict;
 use warnings;
 my ($txn_name, $repo_path) = @ARGV;
 my $svnlook = "D:\\Subversion\\bin\\svnlook.exe";
 my $committer = `$svnlook author $txn_name $repo_path`     or die("Unable to get committer with svnlook.\n");
chomp($committer);
my $commitlog = `$svnlook log $txn_name $repo_path`     or die("Unable to get log message with svnlook.\n");
my ($cnr_number) = $commitlog =~  /^CNR\d+/; or die("You must enter a valid CNR\n");
 
Are you sure you copied and pasted your code correctly? I get a syntax error at the unwanted semi-colon on the last line.

Anyway, the $commitlog =~ /^CNR\d+/ expression is not going to return the matched, it just returns a true or false (1 or 0) depending on whether the match occurred or not. The actual matching value will be in $&, so try this perhaps:

Code:
[red]([/red][blue]$commitlog[/blue] =~ [red]/[/red][purple]^CNR[purple][b]\d[/b][/purple]+[/purple][red]/[/red][red])[/red] or [url=http://perldoc.perl.org/functions/die.html][black][b]die[/b][/black][/url][red]([/red][red]"[/red][purple]You must enter a valid CNR[purple][b]\n[/b][/purple][/purple][red]"[/red][red])[/red][red];[/red]
[url=http://perldoc.perl.org/functions/my.html][black][b]my[/b][/black][/url] [blue]$cnr_number[/blue] = [blue]$&[/blue][red];[/red]

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top