hi! I'm writing a program to scan for all wireless networks in range, create profiles for them, and automatically connect to the strongest network in range I have a stored profile for or the strongest unencrypted network. The info I need to get online is stored in a file data.txt with each profile seperated by a \x17. These profiles are read into an array @inputs. I am scanning for networks using iwlist scan (gentoo linux command) and reading the output from that into an array @profiles, with each network being one element. here's my problem-- I'm using a regex to find any network that appears in both @inputs and @profiles, now I need to figure out how to select that element of @inputs so I can read the data into iwconfig and get online. Here's my code

Unanswered questions are like "Thorn In Flesh", a bit of pain and does not looks nice to

eye for whatever the reasons.

For a moment, forget everything else about networks and all that --

Put simply, you have two text files and you want to pull out comman elements base on user essid If so please check that split on @inputs (I suspect) there in lies the problem and use print statements wherever in doubt.

A advise for that input separator Remember to use "local" before $/ ALWAYS else the default "\n" is changed and it may lead to problems.

Code

-For all my suggestions " I am sure someone else can do it in a better or elegant manner!"

what is local? i've never heard of that...I am mostly teaching myself perl, so Im sure there are several things i've missed. $/ is only set to 'Cell ' in this particular scope...I only pasted the one subroutine I was having problems with. Unless it needs to be something specific it is set as '\n' in every other scope.

I think I might have solved my problem....I'm going to write a subroutine to return the profile I want to select and assign it as a variable, then call for that variable when I want to read from the profile. Now I'm off to write it! thanks!

This sarcasm was totally unnecessary and uncalled for. In a public forum you should not always expect exact responses to your questions and you should be tolerant enough for the rest or if you feel that a particular response is ludicrous you can send a private mail, to the person; this is a decent way to do it. It seems you are young (and immature).

Quote

-For all my suggestions " I am sure someone else can do it in a better or elegant manner!"

To the best of my understanding; even as you think that my earlier post was laughable but I must tell you very honestly that when I spent my time on your post I found problem with the following in your code

Code

@lines = split (/\n/, $input)

and it was not doing what was expected.

In fact I was thinking not to split on "\n" and --- but as you say you have solved your problem on your own let's just forget it all -For all my suggestions " I am sure someone else can do it in a better or elegant manner!"

Use of uninitialized value in string eq at ./connect.pl line 69, <SCAN> chunk 4. Use of uninitialized value in string eq at ./connect.pl line 69, <SCAN> chunk 4. Use of uninitialized value in string eq at ./connect.pl line 69, <SCAN> chunk 4. Goose

I can't figure out why I keep getting the uninitialized values...its more or less doing what its supposed to by printing "Goose" which is the essid of the only network im in range of right now. Line 69 is

Code

if ($1 eq $essid)

You are right, vikas.deep its something to do with my split, $essid is the uninitalized value. I'm getting the error 3 times and have 3 profiles in @inputs, so its happening on every iteration of my foreach loop. However it is matching $1 and $essid, and printing the correct profile...why would $essid be uninitialized if its finding the right profile?

And I wasn't being sarcastic, sorry if it came off that way. I didn't understand your post and was asking you to clarify.

This sarcasm was totally unnecessary and uncalled for. In a public forum you should not always expect exact responses to your questions and you should be tolerant enough for the rest or if you feel that a particular response is ludicrous you can send a private mail, to the person; this is a decent way to do it. It seems you are young (and immature).

Quote

It didn't seem sarcastic to me, seemed like a reasonable question. -------------------------------------------------

I am sorry (if that was not a sarcasm) for that misunderstanding. Please go through the following even if it may seem a bit out of topic, for every one (I believe) is here to gain knowledge, share experiences and above all make friends in the spirit of common universal brotherhood.

You see english is not my first language and today Indians speak English only because we were ruled over by British for well over a century (just like contemporary Hindi is a mix of pure hindi and persian brought by mughals to this land and which also gave birth to a new language urdu) and leading social reformers and modern thinking Indians of that time demanded english education for Indian masses and of course after India attained her freedom the special efforts that democratically elected government has put in towards this end. So today we are very unique population where every one is at least bilingual speaking his native language (usually Hindi or some other regional language) and english.

Middle classes are in particular Hindi speaking and english reading people, for official purposes we speak and work in english but in day to day life we are hindi speaking people.

All this is necessary to say here because I am a serious learner, (using my real name and email id and location) and plan to gain as much as I can from here and so I plan to stay here for long.

Even though english has emerged a common link language world over but semantics may differ. Also culture and environment matter a lot.

In my place, a person who has written a few subroutines and he is saying that this is only a part of the script that means he has written a pretty long piece of Perl code and then he is asking for what is "my" or "local" before a variable declaration in response to a person who asks him to do so is looked very suspiciously

(and in fact a unhealthy, unpleasant slang is used for such an attempt that "he is trying to make you ***(C-word)")

that is why i thought that it was a sarcasm. (and anyway Yesterday was a rough day and you know that I was at receiving end in beginners section also)

I am happy that things have cleared over here. and Yes when I worked out that problem I clearly saw that there was a problem there in that split and now he is getting warnings because there is nothing to split there and in fact that split is useless beacuse he can and should directly use whatever he is getting from @inputs. I will again go through the whole thing to the best of my ability.

and yes within the confines of a subroutine and within {}; may be "local" might not be essential (I am not very confident about this) but I am in a habbit of invariably usinglocal when ever I have to play with input separator. May be here I was wrong for suggesting local here but that was the first thing that struck my mind (Hey! why this man is not using "local" while playing with input separator).

I will go through the relevant documentation and get back on that

Quote

"local" Now that is "the" thorn in flesh here

-For all my suggestions " I am sure someone else can do it in a better or elegant manner!"

"Use of uninitialized value in string " may just be warnings and if you do not use warnings in your code these messages should disappear. Here, of course you are having a "Goose" that you are able to print but in the sample that I tested there was no "Goose" and so I was not able to print anything.

Yesterday, was a bit rough day and I was angry with some things and also particularly with myself and got just a bit touchy but all that is past and today I will re-read the entire thing here and get back.

Quote

-For all my suggestions " I am sure someone else can do it in a better or elegant manner!"

"Use of uninitialized value in string " may just be warnings and if you do not use warnings in your code these messages should disappear. Here, of course you are having a "Goose" that you are able to print but in the sample that I tested there was no "Goose" and so I was not able to print anything.

Thanks, I am using strict and warnings, so your right I guess that is why I'm getting those warnings. I just didn't know if it would mess up anything later in the code, or if I could ignore them or take off warnings.

This program won't run correctly unless you create a data.txt file in a specific format and use the iwlist scan command for linux, so it sorta depends on what OS you are using whether or not you get the intended results.

This was what I actually meant you might be thinking that you have set input separator to "CELL" only in that subroutine and rest of the script it is default "\n" but it is never so, even if in any one sub routine you do not use "local" it gets changed everywhere and any other subroutine using the same string will give you spurious results.

I thought a person who has written a perl code with few sub routines and especially involving input separator might be knowing this thing and he is simply trying to have fun and all that ----

As you have worked yourself a way out good but now I don't think you will ever have a problem with "local". Also please see

Quote

Localization of special variables

If you localize a special variable, you'll be giving a new value to it, but its magic won't go away. That means that all side-effects related to this magic still work with the localized value.