The postfix if (! $line=~m/^\s*exit\s*$/i) is not doing what you expected.

#!/usr/bin/env perl use strict; my $line = 'not an exit statment'; print "line matched ! =~\n" if (! $line =~ m/^\s*exit\s*$/i ); print "line matched !(=~)\n" if (! ($line =~ m/^\s*exit\s*$/i) ); print "line matched not =~ \n" if (not $line =~ m/^\s*exit\s*$/i ); print "line matched if !~\n" if ( $line !~ m/^\s*exit\s*$/i ); print "line matched unless =~\n" unless ($line =~ m/^\s*exit\s*$/i); __END__ line matched !(=~) line matched not =~ line matched if !~ line matched unless =~

The ! operator has a much higher precedence than the not operator does. Using parentheses with the ! applies it to the result of the match; not with its lower precedence does so by default.

When $exp->send sends the exit command to isql, isql disconnects and Expect.pm notices and handles that. If you are writing a production-quality program - especially one that will run automatically - you'll want to code your own checks for errors, disconnects, etc. OTOH, if this is for your own use only, run manually to simply automate a task, then you can usually get away with letting the Expect module handle anomalies. (I assume you're backing up whatever DB objects are being modified prior to letting a program make changes...)


Update: added != and unless tests as additional examples

In reply to Re^4: problems using Expect.pm in foreach loop by keszler
in thread problems using Expect.pm in foreach loop by gg48gg

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.