On Wed, Nov 12, 2008 at 13:51, JC Janos <[EMAIL PROTECTED]> wrote:
> Hi,
>
> The two cases in this test program both print out the same data; in
> this case, the 'whois record',
>
> #!/usr/bin/perl
> use strict;
> use warnings;
>
> my $ip = "1.2.3.4";
>
> # CASE: variable
> my $WHOIS1 = '/usr/bin/whois';
> system("$WHOIS1 $ip");
>
> # CASE: constant
> use constant WHOIS2 => '/usr/bin/whois %s';
> my $cmd = sprintf(WHOIS2, $ip);
> system($cmd);
>
> Is either case the better or correct usage here? Or are they simply
> interchangeable?
>
> --JC
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> http://learn.perl.org/
>
>
>
You may want to also look at Readonly*. The major differences amongst
my $WHOIS1 = '/usr/bin/whois';
Readonly my $WHOIS2 = '/usr/bin/whois';
use constant WHOIS3 => '/usr/bin/whois';
are:
$WHOIS1 can be modified (not good) and can't be optimized away by the
compiler (possible performance impact)
$WHOIS2 cannot be optimized away by the compiler (possible performance impact)
WHOIS3 cannot be interpolated into strings (annoying)
I tend to use the constant pragma, mostly because Readonly is not part
of Core Perl. That said Readonly is a lot more flexible than the
constant pragma. All of that said, the big problem here is that you
are using a program and then parsing its output. You should really
look into using Net::Whois::Proxy or a similar module instead. Using
external programs is generally a sign that you are doing something
wrong (unless the point of the script is to puppet string an external
utility).
* http://search.cpan.org/dist/Readonly/Readonly.pm
** http://search.cpan.org/dist/Net-Whois-Proxy/lib/Net/Whois/Proxy.pm
--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/