#!/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.


In reply to Re: arch linux small app in perl by jwkrahn
in thread arch linux small app in perl by heatblazer

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.