Perl chomp sets reults 0 to 1

Posted on 2004-10-29
Last Modified: 2006-11-17
this perl script was running fine and all of a sudden it would return an error but the DTS package actually ran...Found out the chomp($results) was changing the value of 0 to 1...but why and all of a sudden?

## pipe stdio to log file
open (STDOUT, "| tee $logfile");
open (STDERR, "| tee $logfile");

## do not buffer STDOUT results
select (STDOUT);
$| = 1;

print "$script is starting\n";
print "Time now = ".FormatTimeDate()."\n";
print "Executing in $development\n";

## change directory
chdir ("$ecsjobs/$jobfolder") || die("Cannot change directory to $ecsjobs/$jobfolder");

print "Executing DTS package $package on $server\n";
$sql = "exec RunDTSPackage $package";

$cmd = "isql -S$server -U$uid -P$pwd -n -b -d$db -Q\"$sql\" ";
print  "isql -S$server -U$uid -n -b -d$db -Q\"$sql\" ";
$results = `$cmd`;
print "$results\n"; *** Here $results = 0
$error = $?;
print "$error\n";
$results = chomp($results);
print "$results\n"; **** here results = 1
if ( ($error != 0) or ($results =~ /Msg/) or ($results =~ /DB-LIBRARY error/) or ($results != 0) ) {
     die ("\n!!! Error DTSing data to USCLWAPGP01\PRODCOD !!!\n");

Question by:dkochenour
    1 Comment
    LVL 11

    Accepted Solution

    hey dkochenour,

    chomp returns a 0 when there is no \n character at the end. it returns a 1 if there is a \n at the end and is chomp(ed) off..

    so you should be actually doing
    chomp($results); # and not $results=chomp($results);

    Have fun,

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    Title # Comments Views Activity
    how to open from address saved in DB? 26 67
    Fix45 challenge 15 50
    mergeTwo  challenge 13 42
    nestparen challenge 4 13
    Purpose To explain how to place a textual stamp on a PDF document.  This is commonly referred to as an annotation, or possibly a watermark, but a watermark is generally different in that it is somewhat translucent.  Watermark’s may be text or graph…
    Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    877 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now