in reply to arch linux small app in perl
#!/usr/bin/perl -w
The first line begins with a space character which means that this will not work properly on Linux unless explicitly called by perl on the command line. To run this as a stand-alone program the first two characters must be '#!'.
Also, most modern perl programs use the warnings pragma instead of the -w command line switch. See: perllexwarn for details.
my $scanned = `iwlist scan`; ... my @lines = split(/\n/, $scanned);
Could also be written as:
chomp( my @lines = `iwlist scan` );
But if you want better error information you might want to use open instead.
if ( $pat =~ m/"/i ) {
The /i option is for a case insensitive match but as far as I know the character '"' does not have different upper and lower versions.
if ( $_ =~ m/ttl/i || $_ =~ m/rtt/i) {
That could be more concisely written as:
if ( /ttl|rtt/i ) {
#trims all quotes from the ESSID string sub trim { my @tr = @_; my @trimmed = split(/"/, $tr[0]); return @trimmed; } ... my $connection = &trim($conn[0]);
trim() returns an array, and an array in scalar context returns the number of elements in the array:
$ perl -le' sub test { my @array = "a" .. "z"; # 26 elements return @array; } my $stuff = test(); print $stuff; ' 26
So your $connection variable will always contain a numerical value. Perhaps you want something like this instead:
( my $connection = $conn[ 0 ] ) =~ tr/"//d;
Please select network by typing it`s name
"it`s" is the contraction of "it is", the possessive form does not have an apostrophe.
The use of an ampersand in subroutine calls is Perl4 style, it is not usually used in Perl5.
Some uses of @array, and then just using $array[0], can be simplified by just using a single scalar instead.
The use of a single string with system might be better with a list instead.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: arch linux small app in perl
by heatblazer (Scribe) on Feb 27, 2012 at 15:59 UTC | |
by jwkrahn (Abbot) on Feb 27, 2012 at 23:28 UTC |