open file failed



Good morning, afternoon, evening for perl enthusiasts of all over the world:)
 
On RedHat Linux, the perl complain "Inappropriate ioctl for device" when I use the following code to open a file:
<CODE>
my $file = "./abc";
if ( open FN, $file )
{
    print "Cannot open the file: $!\n";
    next;
}
</CODE> 
 
If I use the following code however, all is OK!
<CODE>
open FH, ">$file" or die "Cannot open the file: $!\n";
<CODE>
I want to open a few files in a foreach loop in turn , so I need jump one if I cannot open it rather than exit.
 
I modified code and test the FH as following, perl indicate "Bareword "FH" not allowed while "strict subs"".
<CODE>
open FH, $name;
if ( not defined FH )
{
    print "Cannot open input file: $!\n";
    next;
}
</CODE>
 
I'd like someone tell me what happen and what file handle(or socket handle, etc) is in perl really.
 
BTW, why a DOS-style perl file cannot run on linux and the bash report ": bad interpreter: No such file or directory"? It will be OK if I save the file as Unix-style and FTP to linux.
Another question is what is the simplest way to replace "\r\n" with "\r" or "\n"?
 
Thanks.

Attachment: smime.p7s
Description: S/MIME cryptographic signature



Relevant Pages

  • Re: Newbie: Looking for comments on this (working) script
    ... > I've been trying to learn Perl in recent days, ... You could use chomp() here instead of later in map. ... You are declaring @arguments and then pushing values into it. ... With $file now local to the foreach loop you need to add it to the ...
    (comp.lang.perl.misc)
  • Re: perl -e equivalent of short script...
    ... Maybe I'm misunderstanding you, but it sounds like ... frequently calling 'perl -e'. ... I won't quote "the following"; I'll just say that It took me about ... the foreach loop. ...
    (perl.beginners)
  • List Variable becomes undefined inexplicably
    ... Using Perl v5.8.4 ... I was able to reproduce it with the test script below. ... subroutine A, iterated over in a foreach loop in subroutine B, is then ... sub ITERATE_HOSTS { ...
    (comp.lang.perl.misc)
  • Re: perl -e equivalent of short script...
    ... you're saying that you're writing shell scripts in which you're ... frequently calling 'perl -e'. ... the foreach loop. ...
    (perl.beginners)
  • Re: Newbie that needs some help
    ... > Your foreach loop is in the inner most loop, so your @lines is only going ... There is nothing wrong with the syntax or perl would report a syntax ... The idiom 'foreach ($scalar) ' is very useful in perl. ...
    (perl.beginners)