In most perl examples, it used this method to trap error:
open(INFILE, $fname) or die "Unable to open $fname";
process_file();
close(INFILE)
other_codes();
Now that if I don't want to die after the open so as to run
other_codes()? Could I test the value of file handle INFILE like what I
did with C?
fhandle=fopen(f name,"r")
if (fhandle > 0) {
process_file();
fclose(fhandle)
}
else
show_error()
other_codes();
--
.~. Might, Courage, Vision. In Linux We Trust.
/ v \ http://www.linux-sxs.org
/( _ )\ Linux 2.4.22-xfs
^ ^ 5:00pm up 2 days 18:54 load average: 1.00 1.00 1.00
Jul 19 '05
15 6039
toylet <toylet_at_mail .hongkong.com> wrote: hmm... how do you force a variable into a certain context (could I also call it "type casting")?
You almost never need to. About the time string/number matters is with
magic values like $!; other than that, scalar context can be forced with
scalar() or unary + and list context with parentheses ().
for integer, $i+0 or (int)$i.
yes no, though int($i) will give you int rather than
float
for string, $i+""? or is it (string)$i?
$i.'' or "$i" no
for array for hash
eh what? Please explain what you expect, e.g., (hash)$i to achieve?
Ben
--
And if you wanna make sense / Whatcha looking at me for? (Fiona Apple)
* be*@morrow.me.u k *
>> for array for hash
eh what? Please explain what you expect, e.g., (hash)$i to achieve?
Just asking for a general method of forcing context.
--
.~. Might, Courage, Vision. In Linux We Trust.
/ v \ http://www.linux-sxs.org
/( _ )\ Linux 2.4.22-xfs
^ ^ 3:24pm up 4:33 1 user 1.79 1.45
Ben Morrow <us****@morrow. me.uk> wrote in comp.lang.perl. misc: toylet <toylet_at_mail .hongkong.com> wrote: hmm... how do you force a variable into a certain context (could I also call it "type casting")? You almost never need to. About the time string/number matters is with magic values like $!; other than that, scalar context can be forced with scalar() or unary + and list context with parentheses ().
Parentheses only provide list context on the left side of an assignment
(anywhere else?). Watch this:
sub wanta { print wantarray ? "array\n" : "scalar\n" }
$x = wanta;
( $x) = wanta;
$x = ( wanta);
( $x) = ( wanta);
The parentheses on the right side don't seem to do anything.
I can't meaningfully say much about the difference between unary +
and scalar(), except that there is one. Vaguely, "+" can change parsing,
scalar() can't.
[...]
And if you wanna make sense / Whatcha looking at me for? (Fiona Apple)
Can't say I understand that sig of your's, but I like it :)
Anno
Ben Morrow <us****@morrow. me.uk> wrote in comp.lang.perl. misc: toylet <toylet_at_mail .hongkong.com> wrote: hmm... how do you force a variable into a certain context (could I also call it "type casting")? You almost never need to. About the time string/number matters is with magic values like $!; other than that, scalar context can be forced with scalar() or unary + and list context with parentheses ().
Parentheses only provide list context on the left side of an assignment
(anywhere else?). Watch this:
sub wanta { print wantarray ? "array\n" : "scalar\n" }
$x = wanta;
( $x) = wanta;
$x = ( wanta);
( $x) = ( wanta);
The parentheses on the right side don't seem to do anything.
I can't meaningfully say much about the difference between unary +
and scalar(), except that there is one. Vaguely, "+" can change parsing,
scalar() can't.
[...]
And if you wanna make sense / Whatcha looking at me for? (Fiona Apple)
Can't say I understand that sig of your's, but I like it :)
Anno
toylet wrote: for array for hash
eh what? Please explain what you expect, e.g., (hash)$i to achieve?
Just asking for a general method of forcing context.
($a,$b) = foo(); # List context
@array = foo(); # List context
%hash = foo(); # List context
foo(); # Null context
$var = foo(); # Scalar context
$var = +foo(); # Numeric scalar context
$var = foo().""; # String scalar context
if (foo()) {}; # Boolean scalar context
-Joe
[ F'up set to clpm;
comp.lang.perl doesn't exist ]
Also sprach Joe Smith: toylet wrote: Just asking for a general method of forcing context.
($a,$b) = foo(); # List context @array = foo(); # List context %hash = foo(); # List context foo(); # Null context $var = foo(); # Scalar context $var = +foo(); # Numeric scalar context
Nope. This does not force numeric context. This does:
$var = foo() + 0;
Or this:
$var = foo() * 1;
Any numeric operator in conjunction with the neutral element with
respect to the used operator can be used to enforce numeric context.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_ $;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus}) (rekcah{lrePbus })(lreP{rehtona bus})!JAPH!qq(r ehtona{tsuJbus# ;
$_=reverse,s+(? <=sub).+q#q!'"q q.\t$&."'!#+sex isexiixesixeseg ;y~\n~~dddd;eva l This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Nathan Bloomfield |
last post by:
Hi there,
I am having difficulty with a piece of code which would work wonders
for my application if only the error trapping worked properly.
Basically, it works as follows:
- adds records from rsSource into rsDest
- if it finds a key violation then it deletes the current record from
rsDest and adds the new record from rsSource. This works perfectly -
but only for the first found duplicate record, it brings up the error
|
by: Neil |
last post by:
Is there a way to trap an error generated in another app that is controlled
via automation? I have an Access 2000 app that opens Word 2000 and proceeds
to open a series of documents and, in each document, parse the contents and
write it to an Access table (the Access app, after opening Word, runs a
macro within Word which parses and writes to the Access app via DAO).
Occasionally we get an error from Word (such as "document is locked for...
|
by: windandwaves |
last post by:
Hi Gurus
Does anyone know how I set the error trapping to option 2 in visual basic.
I know that you can go to tools, options and then choose on unhandled errors
only, but is there a VB command that I can use instead?
Cheers
Nicolaas
|
by: Thelma Lubkin |
last post by:
I use code extensively; I probably overuse it. But I've been using
error trapping very sparingly, and now I've been trapped by that.
A form that works for me on the system I'm using, apparently runs into
problems on the system where it will actually be used, and since I
used so little error-trapping it dies very ungracefully.
I will of course try to fix whatever is causing the error and add
error-trapping to the functions where the...
|
by: Bill |
last post by:
Despite our best efforts occasionally in an aspx file, something like <%=x%>
where x is not defined sqeaks by and I get the ugly asp error message. I want
to be able to identify this particular error and issue a pretty message. I
use the global.asax on application error to handle generalized error
handling. I want to be able to capture and identify the above error.
| |
by: SMG |
last post by:
Hi ,
Sory for incomplete message in last post here is the actual problem..
I am using following code in web.confiig for trapping all the error through
out my site..
<customErrors mode="On" defaultRedirect="WebForm1.aspx">
<error statusCode="404" redirect="ServerError.aspx"></error>
<error statusCode="500" redirect="WebForm3.aspx"></error>
|
by: Fred Nelson |
last post by:
I'm devloping a VB.NET web application and I'm having a problem with
trapping errors and logging the cause of them. When an unexpected error
occurs I want to write it to a file - or e-mail it to me. I have set up
everything according to the documentation however when I get to my error
page "errorpage.aspx" I can't determine why I'm there!
In my web.config file I have the line:
<customErrors ... defaultredirect="errorpage.aspx">
In...
|
by: sara |
last post by:
I have a procedure to automate bringing several Excel files into our
Access tables, on a daily basis.
The problem is that if the user has a problem, and tries to run the
import again (maybe 3 files imported then there was a data problem and
they want to re-import after fixing the problem), I can't get the Error
handling to fire if the user is attempting to import duplicate key
records.
Message when I try to import records already on...
|
by: Captain Nemo |
last post by:
I'm still using Office 2000 myself, but some of my clients have Office 2003.
I've recently added a piece of code to create an instance of Word, open a
document, fill in the blanks and become visible so the document can be
printed and/or modified.
This all takes place within one form, in which the Word.Application and
Word.Document objects are both private form-level variables. Just to be on
the safe side I included this piece of code in...
|
by: 47computers |
last post by:
Pretty new to PHP, I recently started learning about error trapping.
As of right now, I include the following into a page in my website:
-------BEGIN PASTE--------
error_reporting(E_ERROR | E_PARSE);
set_error_handler("SendErrorReport");
function SendErrorReport($errorNumber, $errorMessage, $errorFile,
$errorLine, $vars)
{
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |