Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

•Re: Re: Perl & C/C++

by merlyn (Sage)
on Mar 28, 2003 at 17:46 UTC ( [id://246521]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://246521]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-23 07:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found