Perl error checking question

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl error checking question
# 1  
Old 09-10-2008
Perl error checking question

I am not very good with perl but trying to force myself to start learning...
I have a script that calls three other scripts in variables. I want to use a if statement to check the exit status and not sure how to do it..

This is basically what I have, the individual scripts print either a Y or N.
        if ($COMMAND1 eq "N" || ($COMMAND2 eq "N" || ($COMMAND3 eq "N" ) {
                print "something here";
        } else {
                print "something else";

This works, but I don't like it and it should be done with the exit status. I was reading up on this site....
Perl Special Variables

"$! When used in a numeric context, holds the current value of errno. If used in a string context, will hold the error string associated with errno.
$@ Holds the syntax error message, if any, from the last eval() function call."

I am just not sure how to implement it.
# 2  
Old 09-11-2008
By using backticks you are capturing the output of the shell command. This is not the same as its exit status.
For the exit status you need $? following your `STRING` (see perlop) or a system call (see perlfunc). Then the exit status is $?>>8 (read about $? in perlvar).
$status = $? >> 8;

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Checking the user input in perl for characters and length

My question is basically as the title says. How can I check a user inputted string is only certain characters long (for example, 3 characters long) and how do I check a user inputted string only contains certain characters (for example, it should only contain the characters 'u', 'a', 'g', and 'c')... (4 Replies)
Discussion started by: Eric1
4 Replies

2. Shell Programming and Scripting

Question on sync 2 folders with checking files' modify date

Hi Linux Community I would like to ask about how to compare files in deferent server with date. Those A and B servers has the same folder, I have write a sample script to "ls" both folders and "diff" them, and then "rsync" the missing files. It was running well, both A and B are sync, until... (2 Replies)
Discussion started by: lunaticdawn
2 Replies

3. Shell Programming and Scripting

checking co-presence of Var. - Shell or Perl

Hey fellas, I've posted this problem a few days back and I received just one post which was in PHP that I have no idea about! (Thanks to DGPickett) It would be so nice if you can help me with this in Shell or Perl. Here is the story: I have a big table with variables and observations. I... (9 Replies)
Discussion started by: @man
9 Replies

4. Shell Programming and Scripting

Need Suggestions to improve Perl script for checking malformed braces/brackets

Hi all, I've written a Perl script below that check and report for malformed braces. I have a UNIX ksh version and it took a couple of minutes to run on a 10000+ lines. With the Perl version it only took about 20 seconds so that is enough incentive for me to go Perl not to mention that I need... (1 Reply)
Discussion started by: newbie_01
1 Replies

5. BSD

Question: OpenBSD command line for checking list of library used by daemon

Hi All, I would like to ask what is the command line on OpenBSD which able to be used to check the list of library which used by specific daemon? For example, I would like to check what are the libraries which are used by ftpd. Thank you in advance. Regards, Stefan (2 Replies)
Discussion started by: lcxpics
2 Replies

6. Programming

Error Checking

Hey guys i am facing a problem in my sql statement. I am trying to check if there is such a value in the database. Code: string NewMovie = "ww"; string queryText ; queryText = "Select * from movie_info WHERE movie_title = '"+ NewTitle +"'"; ... (1 Reply)
Discussion started by: gregarion
1 Replies

7. Shell Programming and Scripting

checking the request for urls - perl

hi everybody . i'm trying to extract a bunch of urls from an http request but when i do that i get nothing . here it's my code use LWP::UserAgent; $url = "$ARGV"; $ua = LWP::UserAgent->new; $req = HTTP::Request->new(GET=>$url); $res = $ua->request($req); if... (0 Replies)
Discussion started by: KiD0
0 Replies

8. UNIX for Dummies Questions & Answers

perl scripting for checking if a process is running

Hi All, I am new to perl and have been trying to write a short script to check a process.Though i havent reached to the stage where i can match the output. I am trying to pass a variable x with value /opt/RGw/csbp-base/CSBP_BAT.01.00.05/csbp_BAT.01.00.05.jar and then pass another variable... (2 Replies)
Discussion started by: pistachio
2 Replies

9. Shell Programming and Scripting

Opening Files and checking contents in Perl

Hi All, I need some expert help in performing the following in Perl. I have a code below but it doesn;t seem to work. Can any expert give me some advice? Below are the requirements 1) Open numerous files assigned to an array @FILES. Note that the files are always named with the term... (7 Replies)
Discussion started by: Raynon
7 Replies

10. Shell Programming and Scripting

Perl data type checking

I am using perl 5.8.0. I need to check some values to see it they are floats. Our system does not have Data::Types so I can't use is_float. Is there something else that I can use? The only thing in Data is I am not allowed to download anything to our system so I have to use what I have.... (3 Replies)
Discussion started by: ajgwin
3 Replies
Login or Register to Ask a Question

Featured Tech Videos