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

Wouldn't it have been simpler to generate that huuge array dynamically as:
my @COLOR; { local *ARGV; @ARGV = qw(/usr/lib/X11/rgb.txt); while (<>) { push @COLOR, $1 if /\d+\s+\d+\s+\d+\s+(\S+)/; } }
Or better yet, just generate a random RGB on each hit?

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

Replies are listed 'Best First'.
Re: Perl & C/C++
by crenz (Priest) on Mar 29, 2003 at 16:31 UTC

    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).

      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.