in reply to •Re: Re: Perl & C/C++
in thread Perl & C/C++

Just wondering... is there any specific reason why you use @ARGV and <>? Methinks it would be cleaner to just open() and close() the file. Also, this way you could choose not to die if the file doesn't exist (e.g. on Windows).

Replies are listed 'Best First'.
•Re: Re: Perl & C/C++
by merlyn (Sage) on Mar 29, 2003 at 17:02 UTC
    It's only a warning if the file doesn't exist. Not death.

    And for safety, I have to localize a filehandle anyway... so as long as I am doing that, if I pick *ARGV, I get the diamond for free.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

      Any reason not to just use a lexical variable for the handle? You can also get rid of the $1 if since push imposes list context on the regex anyway.
      my @COLOR; { open my $fh, "<", "/usr/lib/X11/rgb.txt" or last; push @COLOR, /\d+\s+\d+\s+\d+\s+(\S+)/ while <$fh>; }

      Makeshifts last the longest.