in reply to Re: arch linux small app in perl
in thread arch linux small app in perl

OK, I`ll fix it. The question is how the statement:

 return @some_array;

would not return all array values like return $a, $b $c... etc? My trim() returned the names without the ' " '. I am still getting used to perl`s syntax since I came from JS/HTML/C. I`ll make it more readable in the future.

I got the error!

my @connection = &trim($conn[0]); if (system("iwconfig wlan0 essid $connection[0] key s:$pawd " +) ) { return 1; }

This should fix it, right?

Replies are listed 'Best First'.
Re^3: arch linux small app in perl
by jwkrahn (Abbot) on Feb 27, 2012 at 23:28 UTC
    The question is how the statement:
    return @some_array;
    would not return all array values like return $a, $b $c... etc?

    Because the subroutine is called in SCALAR context and the context affects the return value(s).    A list (like $a, $b, $c) called in SCALAR context would return the last element of the list.    You can use the wantarray operator to determine what context the subroutine was called in.



    I got the error!

    What error did you get?



    my @connection = &trim($conn[0]); if (system("iwconfig wlan0 essid $connection[0] key s:$pawd " ) ) {

    Now you are calling trim in LIST context but you appear to only need the first element of the returned list.    Perhaps you should only return the first element if that is all you require:

    sub trim { my ( $tr ) = @_; return ( split /"/, $tr )[ 0 ]; }