Is there any way to detect the open error when using an anoymouns
Is there any way to detect the open error when using an anoymouns
am 21.03.2007 14:44:34 von Takushi Usami
Hello.
I would like to detect an open error when using an anonymous handler by designating the undefined scalar variable to open function.
How do I do?
This is a snip of code.
----------
open(my $fh, "non-exist-file");
unless (defined $fh) {
print "cannot open the file";
return;
}
----------
Best,
Takushi.
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Is there any way to detect the open error when using an
am 21.03.2007 14:58:09 von vtatila
Takushi Usami wrote:
> I would like to detect an open error when using an anonymous handle
> by designating the undefined scalar variable to open function.
> open(my $fh, "non-exist-file");
You can use the return value of open and the value of the error variables $=
! =
or $^E just as you normally would. See perldoc -f open and perldoc perlvar. =
FOr example:
C:\>perl -e "open my $file, '<', 'no such thingy' or die qq|Open: $^E\n|"
Open: The system cannot find the file specified
-- =
With kind regards Veli-Pekka Tätilä (vtatila@mail.student.oulu.fi)
Accessibility, game music, synthesizers and programming:
http://www.student.oulu.fi/~vtatila/ =
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Is there any way to detect the open error when using an
am 21.03.2007 15:20:20 von Brian Raven
Takushi Usami <> wrote:
> Hello.
> =
> I would like to detect an open error when using an anonymous handler
> by designating the undefined scalar variable to open function. =
> =
> How do I do?
> =
> This is a snip of code.
> ----------
> open(my $fh, "non-exist-file");
> unless (defined $fh) {
> print "cannot open the file";
> return;
> }
> ----------
First, it's a lexically scoped file handle, not anonymous, but
congratulations for using it. Second, the three argument form of open is
generally preferred these days. For example:
my $fn =3D "non-exist-file";
open my $fh, "<", $fn or die "Failed to open $fn: $!\n";
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: Is there any way to detect the open error when using
am 21.03.2007 16:00:58 von Bill Luebkert
Brian Raven wrote:
>
> Second, the three argument form of open is
> generally preferred these days. For example:
>
> my $fn = "non-exist-file";
> open my $fh, "<", $fn or die "Failed to open $fn: $!\n";
Preferred by whom ? I don't think I've ever used it once. ;)
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Is there any way to detect the open error when
am 26.03.2007 14:59:18 von Brian Raven
Bill Luebkert <> wrote:
> Brian Raven wrote:
>> =
>> Second, the three argument form of open
>> is generally preferred these days. For example:
>> =
>> my $fn =3D "non-exist-file";
>> open my $fh, "<", $fn or die "Failed to open $fn: $!\n";
> =
> Preferred by whom ? I don't think I've ever used it once. ;)
I see it recommended on comp.lang.perl.misc quite often. I have been
using it fairly exclusively for at least a couple of years.
Sorry for not responding sooner, but I have been a little tied up
recently.
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: Is there any way to detect the open error
am 26.03.2007 15:28:16 von Bill Luebkert
Brian Raven wrote:
>
> I see it recommended on comp.lang.perl.misc quite often. I have been
> using it fairly exclusively for at least a couple of years.
Well, I take that with a grain of salt - I recommend using whatever
you number of args you like. ;)
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs