[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]



--- Object ---


package SAM::Util;
use Expect;
use strict;

sub test_regex {
  my ($self, $reg) = @_;
  my $pid = fork();

  do {
    wait;
    return ( $? ? undef : 1);
  } if $pid;

  open(F, " < /dev/null");

  my @R = ();

  my $handler = sub {
    my $self = shift;
    exp_continue;
  };

  push @R, [ '-re', $reg, $handler];
  my $exp = Expect->exp_init(\*F);

  eval {
    $exp->expect(0, at R);
  };
  if($@) {
    exit 1;
  }
  exit 0;
}

return 1;

--- Test code ---
use SAM::Database;
use SAM::Util;
use Getopt::Std;
use strict;


#
# Static variables
#
my $test_regex = undef;
my $database = undef;

sub args {
  getopts('t:d:');
  $test_regex = $Getopt::Std::opt_t;
  $database = $Getopt::Std::opt_d;
  return;
}

args;

do {
  my $db = SAM::Database->new();
  $db->connect($database);
  my @T = $db->get_triggers();
  foreach my  $ref (@T) {
    next unless $ref->{'criteria_type'} eq 'R';
    print "$ref->{'name'}: ";
    my $res = SAM::Util->test_regex($ref->{'criteria'});
    print ( $res ? "syntax ok" : "syntax incorrect" );
    print "\n  $ref->{'criteria'}\n" unless $res;
    print "\n";
  }
  exit 0;
} if $database;

die "regex_text.pl <regular express>\n" unless $test_regex;
my $res = SAM::Util->test_regex($test_regex);
print ( $res ? "syntax ok" : "syntax incorrect" );
print "\n";

# vi: set ts=2 sw=2: #



On Tue, 2004-08-03 at 13:16, Geoffrey wrote:
> I'm really enjoying the Perl tutorials from Fletch, but I'm thinking 
> it's about time he billed Christopher. :)


</pre>
<!--X-Body-of-Message-End-->
<!--X-MsgBody-End-->
<!--X-Follow-Ups-->
<hr>
<!--X-Follow-Ups-End-->
<!--X-References-->
<ul><li><strong>References</strong>:
<ul>
<li><strong><a name="00083" href="msg00083.html">[ale] Using Expect.pm</a></strong>
<ul><li><em>From:</em> cfowler at outpostsentinel.com (Christopher Fowler)</li></ul></li>
<li><strong><a name="00084" href="msg00084.html">[ale] Using Expect.pm</a></strong>
<ul><li><em>From:</em> fletch at phydeaux.org (Fletch)</li></ul></li>
<li><strong><a name="00087" href="msg00087.html">[ale] Using Expect.pm</a></strong>
<ul><li><em>From:</em> esoteric at 3times25.net (Geoffrey)</li></ul></li>
</ul></li></ul>
<!--X-References-End-->
<!--X-BotPNI-->
<ul>
<li>Prev by Date:
<strong><a href="msg00087.html">[ale] Using Expect.pm</a></strong>
</li>
<li>Next by Date:
<strong><a href="msg00089.html">[ale] Using Expect.pm</a></strong>
</li>
<li>Previous by thread:
<strong><a href="msg00087.html">[ale] Using Expect.pm</a></strong>
</li>
<li>Next by thread:
<strong><a href="msg00089.html">[ale] Using Expect.pm</a></strong>
</li>
<li>Index(es):
<ul>
<li><a href="maillist.html#00088"><strong>Date</strong></a></li>
<li><a href="threads.html#00088"><strong>Thread</strong></a></li>
</ul>
</li>
</ul>

<!--X-BotPNI-End-->
<!--X-User-Footer-->
<!--X-User-Footer-End-->
</body>
</html>