Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sub list {
- require HTTP::Date;
- import HTTP::Date;
- my $date = [split /s+/, HTTP::Date::time2iso(time())]->[0];
- my $dbh = DBI->connect($dsn, $user, $password)
- || die "cannot connect to $database: $!n";
- my $sql = <<EOSQL;
- SELECT * FROM $table where expiry >= '$date' order by expiry
- EOSQL
- my $sth = $dbh->prepare($sql);
- $sth->execute();
- while (my $ref = $sth->fetchrow_hashref()) {
- my $temp = $template;
- $temp =~ s#__TITLE__#$ref->{'title'}#;
- my $job_spec = $ref->{'job_spec'};
- ...etc...
- $sth->execute();
- my $first = 1;
- while (my $ref = $sth->fetchrow_hashref()) {
- if( $first ) {
- print "We currently have the following vacancies:n";
- $first = 0;
- }
- my $temp = $template;
- ...
- }
- if( $first ) {
- print "No vacancies foundn";
- }
- $sth->execute();
- if($sth->rows) {
- print "We have data!n";
- }
- while(my $ref = $sth->fetchrow_hashref()) {
- ...
- }
- $sth->execute();
- my $ref = $sth->fetchrow_hashref();
- if ($ref) {
- print "We currently have the following vacancies:n";
- while ($ref) {
- my $temp = $template;
- ...
- $ref = $sth->fetchrow_hashref();
- }
- } else {
- print "No vacancies foundn";
- }
- my @results = ();
- while (my $ref = $sth->fetchrow_hashref()) {
- push @results, $ref;
- }
- if ($#results == 0) {
- ... no results
- } else {
- foreach $ref (@results) {
- my $temp = $template;
- ....
- }
- my $output = '';
- $output .= "whatever we would have printed";
- if ($output eq '')
- {
- print 'We have no vacancies.';
- }
- else
- {
- print "We currently have the following vacancies:n" . $output;
- }
- use Lingua::EN::Inflect 'PL';
- $sth->execute();
- my $results = $sth->fetchall_arrayref( {}, $max_rows );
- if (@$results) {
- print "We currently have the following ", PL("vacancy",scalar @$results), ":n";
- for my $ref (@$results) {
- ...
- }
- }
- # count the vacancies
- $numinfo = $dbh->prepare("SELECT COUNT(*) FROM $table WHERE EXPIRY >= ?");
- $numinfo->execute($date);
- $count = $numinfo->fetchrow_arrayref()->[0];
- # print a message
- my $msg = '';
- if ($count == 0) $msg = 'We do not have any vacancies right now';
- else $msg = 'We have the following vacancies';
- print($msg);
- For a non-"SELECT" statement, "execute" returns the number of rows
- affected, if known. If no rows were affected, then "execute"
- returns "0E0", which Perl will treat as 0 but will regard as true.
- my $returnval = $sth->execute;
- if (defined $returnval && $returnval == 0) {
- carp "Query executed successfully but returned nothing";
- return;
- }
Add Comment
Please, Sign In to add comment