![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Exception Handling | bertpereira | Shell Programming and Scripting | 5 | 01-14-2009 09:28 PM |
| MMU exception | Puntino | Linux | 2 | 05-07-2008 12:35 PM |
| How to catch the exception | Vijayakumarpc | UNIX for Dummies Questions & Answers | 0 | 02-08-2007 02:18 AM |
| Help with RPC Exception | ejbrever | HP-UX | 2 | 08-24-2006 02:08 PM |
| RPC Exception - Help | ejbrever | UNIX for Advanced & Expert Users | 0 | 08-21-2006 12:56 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Hi,
I am trying to understand the significance of the special variables $!,$@ and $? in perl. I have a code block as follows: eval { Code Segment 1: #authenticating to the remote server $ftpobj -> login($username,$password) or die "Can't login to $remote_host"; Code Segment 2: #setting up the current working directory $ftpobj -> cwd ($cwd) or die "Can't change directory"; Code Segment 3: #putting the file in remote server $ftpobj -> put($filename) or die "Can't ftp the file:",$!; } [Where $ftpobj is an Net::FTP object and $filename is an invalid filename] In Code Segment 1 and 2,if there were any errors,i can able to catch it using if($@) since the above code is enclosed by eval. But the trapping is not successful in the case of Code Segment 3.Although the control comes inside the conditional loop if($@) after eval,error message is written to the Standard output with this.The error message is: "Cannot open Local file test2.log: No such file or directory at ftp_file.pl line 44" Why is this happening?Exception handling in perl is implemented using eval{} and if($@), but in this case the error is going out-of control and got printed to STDOUT or STDERR Can anyone suggest what is going on and what is the reason for this behaviour? Can anyone explain me what makes $!,$@,$? different in various situations? Your help and support is appreciated! With Regards Dileep |
|
||||
|
Quote:
Regards Dileep |
|
||||
|
My guess is that the misplaced comma in your third segment is causing the error to be lost. You probably mean die "Can't ftp the file: $!" rather than (die "Can't ftp the file"), $! which is what your code currently seems to do, if I managed to get the precedence right.
Where in your code is there a reference to Local file test2.log? Is that the file you are attempting to upload? (What's the value of $filename?) |
|
||||
|
Quote:
But in this case alone ie,putting the file to remote server,error is thrown to the STDOUT/STDERR along with trapping it in $@.I am wondering about this behaviour and looking for the reason and solution. Unfortunately, the possibility you had given(comma) is not the trum card! |
|
|||||
|
"die" takes a list, so that comma is fine. The problem might be in the Net::FTP implementation. Why don't you use the debugger and trace your way through the code?
It's possible to override the die/warn handlers with $SIG{__DIE__} = code; In this way, a module can redirect stderr to stdout, or something like that. It might be the Net::FTP module is doing this. |
|
||||
|
Sorry, yes, you are right, I tested what I thought to be an analogous case here but my test was flawed.
It would be intriguing to find out which part of the code corresponds to "line 44" in the error message. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|