exiting an eval block inside a loop?
exiting an eval block inside a loop?
am 02.03.2007 17:29:06 von Deane.Rothenmaier
This is a multipart message in MIME format.
--===============0786460739==
Content-Type: multipart/alternative;
boundary="=_alternative 005A90C986257292_="
This is a multipart message in MIME format.
--=_alternative 005A90C986257292_=
Content-Type: text/plain; charset="us-ascii"
Gurus,
I've looked in the Camel and Leopard, and they're mum on this topic. Is
it possible/permitted to exit an eval block that's running inside a loop,
or will that break something? Quickie example code:
LABEL: until ($foo eq q{}) {
$foo = $array{$ndx++};
eval {
for ($foo) {
/^abc/o && do {
next LABEL if ($_ =~ /ZZZ$/); # CAN I DO THIS?
# do something
};
/^def/o && do {
next LABEL if ($_ =~ /RST$/);
# do something else
};
}
};
$@ and die "Error in string value";
}
Deane Rothenmaier
Systems Architect
Walgreens Corp.
847-914-5150
"On two occasions I have been asked [by members of Parliament], 'Pray, Mr.
Babbage, if you put into the machine wrong figures, will the right answers
come out?' I am not able rightly to apprehend the kind of confusion of
ideas that could provoke such a question." -- Charles Babbage
--=_alternative 005A90C986257292_=
Content-Type: text/html; charset="us-ascii"
Gurus,
I've looked in the Camel and Leopard, and they're mum on this topic. Is it possible/permitted to exit an eval block that's running inside a loop, or will that break something? Quickie example code:
LABEL: until ($foo eq q{}) {
$foo = $array{$ndx++};
eval {
for ($foo) {
/^abc/o && do {
next LABEL if ($_ =~ /ZZZ$/); # CAN I DO THIS?
# do something
};
/^def/o && do {
next LABEL if ($_ =~ /RST$/);
# do something else
};
}
};
$@ and die "Error in string value";
}
Deane Rothenmaier
Systems Architect
Walgreens Corp.
847-914-5150
"On two occasions I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question." -- Charles Babbage
--=_alternative 005A90C986257292_=--
--===============0786460739==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============0786460739==--
RE: exiting an eval block inside a loop?
am 02.03.2007 18:22:46 von Brian Raven
From: activeperl-bounces@listserv.ActiveState.com
[mailto:activeperl-bounces@listserv.ActiveState.com] On Behalf Of
Deane.Rothenmaier@walgreens.com
Sent: 02 March 2007 16:29
To: activeperl@listserv.ActiveState.com
Subject: exiting an eval block inside a loop?
> Gurus, =
> =
> I've looked in the Camel and Leopard, and they're mum on this topic.
Is it possible/permitted to exit an eval > block that's running inside a
loop, or will that break something? Quickie example code: =
> =
> LABEL: until ($foo eq q{}) { =
> $foo =3D $array{$ndx++}; =
> =
> eval { =
> for ($foo) { =
> /^abc/o && do { =
> next LABEL if ($_ =3D~ /ZZZ$/); # CAN I DO THIS? =
> # do something =
> }; =
> /^def/o && do { =
> next LABEL if ($_ =3D~ /RST$/); =
> # do something else =
> }; =
> } =
> }; =
> $@ and die "Error in string value"; =
> } =
The documentation ('perldoc -f eval') addresses this issue to some
extent. The second from last paragraph (on my installation, at least)
discusses this.
However, you could also have just tried it (the suck-it-and-see approach
is one of the things that Perl is good at). If you did you would have
seen the warning that it causes (you do have warnings enabled, don't
you). You can inhibit the warning (see following example), but it is
better to avoid code that generates warnings as far as possible. If you
really must do it, please make sure that you document what you are doing
and why.
------------------------------------
use strict;
use warnings;
for my $i (1..10) {
# Try with and without the following statement.
no warnings qw{exiting};
eval {
print "i=3D$i\n";
next;
print "bottom of loop\n";
};
die $@ if $@;
}
------------------------------------
HTH
-- =
Brian Raven =
==================== =====3D=
================
Atos Euronext Market Solutions Disclaimer
==================== =====3D=
================
The information contained in this e-mail is confidential and solely for the=
intended addressee(s). Unauthorised reproduction, disclosure, modification=
, and/or distribution of this email may be unlawful.
If you have received this email in error, please notify the sender immediat=
ely and delete it from your system. The views expressed in this message do =
not necessarily reflect those of Atos Euronext Market Solutions.
Atos Euronext Market Solutions Limited - Registered in England & Wales with=
registration no. 3962327. Registered office address at 25 Bank Street Lon=
don E14 5NQ United Kingdom. =
Atos Euronext Market Solutions SAS - Registered in France with registration=
no. 425 100 294. Registered office address at 6/8 Boulevard Haussmann 750=
09 Paris France.
L'information contenue dans cet e-mail est confidentielle et uniquement des=
tinee a la (aux) personnes a laquelle (auxquelle(s)) elle est adressee. Tou=
te copie, publication ou diffusion de cet email est interdite. Si cet e-mai=
l vous parvient par erreur, nous vous prions de bien vouloir prevenir l'exp=
editeur immediatement et d'effacer le e-mail et annexes jointes de votre sy=
steme. Le contenu de ce message electronique ne represente pas necessaireme=
nt la position ou le point de vue d'Atos Euronext Market Solutions.
Atos Euronext Market Solutions Limited Soci=E9t=E9 de droit anglais, enregi=
str=E9e au Royaume Uni sous le num=E9ro 3962327, dont le si=E8ge social se =
situe 25 Bank Street E14 5NQ Londres Royaume Uni.
Atos Euronext Market Solutions SAS, soci=E9t=E9 par actions simplifi=E9e, e=
nregistr=E9 au registre dui commerce et des soci=E9t=E9s sous le num=E9ro 4=
25 100 294 RCS Paris et dont le si=E8ge social se situe 6/8 Boulevard Hauss=
mann 75009 Paris France.
==================== =====3D=
================
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: exiting an eval block inside a loop?
am 02.03.2007 19:03:07 von Deane.Rothenmaier
This is a multipart message in MIME format.
--===============0074444037==
Content-Type: multipart/alternative;
boundary="=_alternative 00632C7786257292_="
This is a multipart message in MIME format.
--=_alternative 00632C7786257292_=
Content-Type: text/plain; charset="us-ascii"
"Suck-it-and-see"?
Okay, tried that, and got the warning you alluded to. Think I'll leave
things the way they are--two separate for switches, one in the eval to do
the work, and one before it to screen. Less elegant, perhaps, but it
doesn't throw hissy fits.
Thanks to all who even thought of answering this dopey question.... B-)
Deane Rothenmaier
Systems Architect
Walgreens Corp.
847-914-5150
"On two occasions I have been asked [by members of Parliament], 'Pray, Mr.
Babbage, if you put into the machine wrong figures, will the right answers
come out?' I am not able rightly to apprehend the kind of confusion of
ideas that could provoke such a question." -- Charles Babbage
--=_alternative 00632C7786257292_=
Content-Type: text/html; charset="us-ascii"
"Suck-it-and-see"?
Okay, tried that, and got the warning you alluded to. Think I'll leave things the way they are--two separate for switches, one in the eval to do the work, and one before it to screen. Less elegant, perhaps, but it doesn't throw hissy fits.
Thanks to all who even thought of answering this dopey question.... B-)
Deane Rothenmaier
Systems Architect
Walgreens Corp.
847-914-5150
"On two occasions I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question." -- Charles Babbage
--=_alternative 00632C7786257292_=--
--===============0074444037==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============0074444037==--