On 2/25/2014 4:36 PM, Bill McCormick wrote:
On 2/25/2014 4:30 PM, Bill McCormick wrote:
What would be the perl'ish way using map or some other sugar to check if
a list of values meet some criteria? Instead of doing something like

my @issues = qq(123,456,a45);
my $max = 999;

for (@issues) {
   die if $_ < 0 or $_ > $max;
}

Revision:

for(@issues) {
   print "issue=[$_]\n";
   die "$_ not a number\n" if $_ ne $_+0;
   die "$_ not in range\n" if $_ < 0 || $_ > $max;
}

Thanks everyone for the speedy replies. I was looking to just use raw perl for this. This is for an svn PRE_COMMIT hook, where issues is a list of bz issues.

PRE_COMMIT {
  my ($svnlook) = @_;

  my ($issue_list) = $svnlook->log_msg() =~ /issue[:]*.*\[(.+)\]/i;
  my @issues = split(/,/,$issue_list);

  error("Hook",0,"No Issues [$issue_list]") if scalar @issues < 1 ;

  for(@issues) {
    error("Hook",0,"Issue [$_] not a number") if $_ ne $_+0;
error("Hook",0,"Issue [$_] not in range [0-$max_issue]") if $_ < 0 || $_ > $max_issue;
  }

};

POST_COMMIT {
  my ($svnlook) = @_;
  my $rev = $svnlook->rev();
  #strip out the leading /var/lib/svn/ and just capture the repo name
  my ($repo) = $svnlook->repo() =~ /\/var\/lib\/svn\/(.+)/;
  #add the the rest of it
  $repo = qq(svn://localhost/svn/) . $repo;
  #get the list of issues
  my ($issue_list) = $svnlook->log_msg() =~ /issue[:]*.*\[(.+)\]/i;

  my @issues = split(/,/,$issue_list);

  my $author = $svnlook->author();

  my @dirs = $svnlook->dirs_changed();
  my $project = $dirs[0];

my $client = RPC::XML::Client->new($bugzilla . 'xmlrpc.cgi', combined_handler => \&_error);



  foreach my $issue (@issues) {
    $logger->trace(qq(Doing POST_COMMIT hook for:
      rev=[$rev],
      repo=[$repo],
      project=[$project],
      issue=[$issue],
      author=[$author])
    );


    my $response = $client->simple_request('VCS.add_commit', {
        Bugzilla_login => 's...@doamin.com', Bugzilla_password => 'f003ar',
        repo => $repo, project => $project,
        bug_id => $issue, revision => $rev,
    });
  }
};



---
This email is free from viruses and malware because avast! Antivirus protection 
is active.
http://www.avast.com



--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to