Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > trapping file i/o error

Reply
Thread Tools

trapping file i/o error

 
 
Ben Morrow
Guest
Posts: n/a
 
      02-22-2004

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)
* http://www.velocityreviews.com/forums/(E-Mail Removed) *
 
Reply With Quote
 
 
 
 
toylet
Guest
Posts: n/a
 
      02-22-2004
>> 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
 
Reply With Quote
 
 
 
 
Anno Siegel
Guest
Posts: n/a
 
      02-22-2004
Ben Morrow <(E-Mail Removed)> 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
 
Reply With Quote
 
Anno Siegel
Guest
Posts: n/a
 
      02-22-2004
Ben Morrow <(E-Mail Removed)> 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

 
Reply With Quote
 
Joe Smith
Guest
Posts: n/a
 
      02-23-2004
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
 
Reply With Quote
 
Tassilo v. Parseval
Guest
Posts: n/a
 
      02-23-2004
[ 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{rehtonabus}) !JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexi ixesixeseg;y~\n~~dddd;eval
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error Trapping and Error Line Number =?Utf-8?B?UGF1bA==?= ASP .Net 3 10-27-2005 11:49 AM
error trapping =?Utf-8?B?TWlrZQ==?= ASP .Net 4 12-14-2004 08:41 PM
Best standard for error trapping? VB Programmer ASP .Net 2 10-25-2004 08:49 PM
Trapping the 404 (resource not found) error Craig Wilson ASP .Net 2 10-08-2004 08:45 PM
Exceeding File Upload max size - trapping error Brett Robichaud ASP .Net 1 04-07-2004 10:29 PM



Advertisments