Perl uninitialized value in numeric gt? - perl

I'm a beginner in Perl and I get this message when I execute my code:
Use of uninitialized value $triggerCheck in numeric gt (>) at
./advanced-daemon.pl line 101.
This is the only error/warning I get when executing my code. The code, itself, works without any problems but I'm wondering what's the problem in that variable?
To reproduce the problem you can use this code:
while(1==1)
{
my $triggerCheck = "10";
if($triggerCheck < 10)
{
print "This var is < 10";
}
$triggerCheck = 9;
sleep 1;
}
Edit: I solved my problem. Sorry for bothering you all :)

There is absolutely nothing wrong with that code that you initially posted. Nor the code that you replaced it with (other than the annoying infinite loop).
It gets no errors or warnings and, when I change the initialisation to "9", it outputs the string.
In fact, given that your error message is complaining about > and there's no such symbol anywhere in your code, you have a serious mismatch between reality and your presentation of it.
Seriously, put together the minimal complete code sample that generates the error and post that. Helping people over the net is hard enough without being hobbled by fiction :-)

Related

Xcode 8 random command failed due to signal segmentation fault 11

I have a strange problem with the new Xcode 8 (no beta version) and swift3.
Once every other 3-4 times that I compile my code I get a 'command failed due to signal segmentation fault 11' error. I just need to enter new empty line, or sometimes changing some spaces, or add a comment (everywhere in the code) and the error disappears and I can compile again.
This is really strange because I'm not changing anything in the code! And sometimes I can compile and it works, then I don't change anything, I compile again and I get the error.
This is really annoying!
I have noticed this is happening since I have installed several 'Firebase' pods (Firebase, Firebase/Auth etc...). But I need them.
Anyone has any suggestion?
PS: I have set the Enable Bitcode of my project to No as many solution suggested, but nothing. In the error message it is not indicated any swift page where the error can be, an example is:
While loading members for 'Class_name' at
While deserializing 'func_name' (FuncDecl #42)
'func_name' is this one:
public class func loginUser(fir_user: FIRUser) {
let user = SFUser()
user.email = fir_user.email
user.isLogged = true
try! sfRealm.write() {
sfRealm.add(user, update:true)
}
var userToAdd = [String:AnyObject]()
userToAdd["email"] = fir_user.email! as NSString
let ref=FIRDatabase.database().reference()
let usersRef = ref.child(childName)
usersRef.setValue([key:value])
}
But then, as I said, I can just enter an empty row in another file and it compiles!
Thanks
I have the same issue i just figure out that i was using xcode 8.1 and the project's working copy was in xcode 8.2.1 so i just re install xcode 8.2.1 and problem got solved. Hope other can get the help trough this.
Ok, it seems that I have found the solution: it is a problem with Firebase and cocoapods, so 2 solutions:
Download Firebase and import into your project
I, instead, updated cocoapods to the last version and it worked. Upgraded Firebase - Now Getting Swift Compile Error
In my case there was some type checking issue deep down the compiler so the editor didn't give error in the gutter but on building the project I was getting signal setmentation fault 11 error:
1. While type-checking 'GetStoreAPIRequestModel' at /Users/.../StoreAPIModel.swift:9:1
2. While type-checking expression at [/Users/.../StoreAPIModel.swift:15:18 - line:15:31] RangeText="[Dictionary]()"
3. While resolving type [Dictionary] at [/Users/.../StoreAPIModel.swift:15:18 - line:15:29] RangeText="[Dictionary]"
So I changed my code from:
var stores = [Dictionary]() {
willSet {
allStores.removeAll()
for model in newValue {
allStores.append(StoreAPIModel(dictionary: model as! Dictionary).getModel())
}
}
}
To (more descriptive dictionary):
var stores = [[String : Any]]() {
willSet {
allStores.removeAll()
for model in newValue {
allStores.append(StoreAPIModel(dictionary: model as [String : AnyObject]).getModel())
}
}
}
This is tricky problem. Issue can be with line of code or syntax. I was getting similar error and it was due to incorrect usage of dictionary. I was trying to increment the value of dictionary element.
Solution is to triage the code, detailed error provide which module has issue, so try commenting part of code until you find the line which is causing the issue.
Hi i had the same issue with FireBase , my problem was that i was extending FIRStorageReference and FIRDatabaseReference and some time it compile successfully some time i get
command failed due to signal segmentation fault 11
so i removed that files and implement the method other way , now everything works fine.
Found my problem when this occurred. (No cocoapods.) I thought I had left the program in a working state, but I was wrong. I am writing a straightforward command-line program. What it does is somewhat general, so I defined all the strings that make it specific in let statements at the top of the program so that I could someday use the program in a different context.
Since that was working so well, I thought I'd be clever and do the same with a filter of an array of dictionaries. I turned:
list.filter { $0["SearchStrings"] == nil }
into:
let test = { $0["SearchStrings"] == nil }
// ...
list.filter(test)
meaning to continue working on the let, but I never went back and did that. Building gave me the segmentation fault error. Defining test as a function fixed the problem.
(Incidentally, I understand how to strip a filtering function down to the terse braces notation in the context of the call to Array.filter, and why that works, but I don't understand why I can't assign the brace expression to a constant and use it as such.)

How can I suppress this superflous debugger output in Eclipse/EPIC?

I have a strange problem with the Perl Debugger in EPIC. When I started using it, all worked fine as expected. I would set breakpoints, run a program in debug mode, step through it ... Then, something must have changed but I have no idea what. Now, the debugger or EPIC or Eclipse, I don't know who, sends tons of output to the console window that have nothing to do with my program but with the - seemingly to me - internals of EPIC or the Perl debugger. Here's a little cutout from this output, there is an endless amount of this and the things my program wants to output just get lost.
What is the problem here? I did not find any setting I could change in the preferences, I don't know what to search for, I couldn't find anything in the EPIC docs.
Edit: one thing I remember is I used "use diagnostics;" in another program that belongs to the project, but that is not run or used by the program that is producing this debug output. Maybe it has something to do with that? Can it "get stuck" and be remembered by the debugger later? I know it sounds silly, but that's all I got.
DB<396> ;{
do 'dumpvar_epic.pm' unless defined &dumpvar_epic::dump_lexical_vars;
my $offset = 0;
my $savout = CORE::select($DB::OUT);
dumpvar_epic::dump_lexical_vars($offset);
CORE::select($savout);
};
12|$forceingest|1|1|17|SCALAR(0x40fb5a4)|3|'0'|1|3
4|$lll|1|2|14|REF(0x2739ff4)|37|Log::Log4perl::Logger=HASH(0x41bbe64)|3|...|1|3
9|$reingest|1|1|17|SCALAR(0x40fbf14)|3|'1'|1|3
13|$secondsPause|1|1|17|SCALAR(0x40fb774)|5|'300'|1|5
4|$tdh|1|2|14|REF(0x40ff0dc)|15|GLOB(0x42e7484)|3|...|1|3
12|$transferDir|1|1|17|SCALAR(0x40f9f24)|31|'c:/temp/xml/transfer/probleme'|2|31
8|$usedata|1|1|17|SCALAR(0x40fbf84)|3|'1'|1|3
6|%datah|1|1|15|HASH(0x40f2f8c)|3|...|1|3
5|#data|1|1|16|ARRAY(0x41002ec)|3|...|1|3
13|#transactions|1|1|16|ARRAY(0x40ff07c)|3|...|1|3
14|#transferFiles|1|1|16|ARRAY(0x40ff04c)|3|...|1|3
7|#tx_ref|1|1|16|ARRAY(0x40feffc)|3|...|1|3
DB<397> ;{
do 'dumpvar_epic.pm' unless defined &dumpvar_epic::dump_lexical_vars;
my $offset = 0;
my $varexpr = <<'EOT';
${$h->{'$lll'}}
EOT
my $subref = \&dumpvar_epic::dump_hash_expr;
my $savout = CORE::select($DB::OUT);
my $savbuf = $|;
$| = 0;
$subref->($offset, $varexpr);
$| = $savbuf;
print "";
CORE::select($savout);
};
3|ALL|1|2|14|REF(0x41d9f64)|15|CODE(0x41dbee4)|3|...|1|3
5|DEBUG|1|2|14|REF(0x41d9ba4)|15|CODE(0x41dbee4)|3|...|1|3
5|ERROR|1|2|14|REF(0x41d737c)|15|CODE(0x41d9b34)|3|...|1|3
5|FATAL|1|2|14|REF(0x41d735c)|15|CODE(0x41d9b34)|3|...|1|3
4|INFO|1|2|14|REF(0x41d748c)|15|CODE(0x41d9b34)|3|...|1|3
3|OFF|1|2|14|REF(0x41d9fe4)|15|CODE(0x41d9b34)|3|...|1|3
5|TRACE|1|2|14|REF(0x41d9ee4)|15|CODE(0x41dbee4)|3|...|1|3
4|WARN|1|2|14|REF(0x41d717c)|15|CODE(0x41d9b34)|3|...|1|3
10|additivity|1|1|17|SCALAR(0x41d52bc)|3|'1'|1|3
Never mind. There is indeed a setting for that under Preferences/Perl EPIC/Enable Debugger Console. I enabled that setting previously because of another weird problem with the debugger (threads wouldn't terminate any more and hang there until Eclipse was restarted), which seemed to work. Disabling it stops the unwanted output. Maybe there's something really weird going on with Perl/EPIC on my computer...

Stanford Calculator app keeps crashing

I'm taking the Stanford iPad and iPhone developer course online at Stanford using Swift and working on creating a Calculator application. (Still a bit new to programming.)
However, it keeps crashing with the error message whenever I select an operator from the calculator.
operandStack = [36.0]
fatal error: unexpectedly found nil while unwrapping an Optional value
(lldb)
and then when I look in ViewController to see what part of the source code is highlighted. It is this:
NSNumberFormatter().numberFromString(display.text!)!.doubleValue }
the error message under this though, reads:
THREAD 1:EXC_BAD_INSTRUCTION(code:EXC_1386_INVOP,subcode=0x0)
I don't understand what's going on, since I entered the code, word for word from the lecture.
Any help is appreciated!
Thanks in advance!
I am stuck at that part of the course too!
I think that apple recently made changes to NSNumberFormatter's numberFromString method. Because when I printed out display.text!, there was nothing wrong. In other words, it does not found nil while unwrapping that part.
Another part we are unwrapping is here, at the second ! mark, we unwrap only this part:
NSNumberFormatter().numberFromString(display.text!)
But we have an error out of this, so numberFromString should be returning nil.
But in the videos, it doesn't. It perfectly turns floating point number strings (such as "36.0") to NSNumber, then to Double.
And since your question was asked on May 20th and I could not find any "old" questions, I think Apple had changed the code on numberFromString.
Edit: I did something crazy and used Find & Replace (command + F) to replace all "Double"s to "Int"s in my code. The multiplication part works well now, I think the problem is about the "." part on Doubles.
Edit 2: I solved it. Some countries such as US use "." to separate decimals and some others such as Turkey use "," to do it. It works on video because he's doing it on US.
NSNumberFormatter has a property called decimalSeparator. We have to set it to ".". I did the following changed to my code and it worked perfect.
var displayValue: Double {
get {
var formatter = NSNumberFormatter()
formatter.decimalSeparator = "."
return (formatter.numberFromString(display.text!)!.doubleValue)
}
set {
display.text = "\(newValue)"
userIsInTheMiddleOfTypingNumber = false
}
}
"found nil while unwrapping an Optional" means that you have a variable that may or maynot have a value, when you use the operator ! you are telling swift "Trust me there is a value in there" however if there is not swift will throw a exception as the one you just saw.
The best way to avoid this is checking before use:
if let value = display.text{
//if your code get here value is safe to use
NSNumberFormatter().numberFromString(value).doubleValue
}

Is there any way to clear NSLog Output?

I have been googling from last couple of hours for finding that is there any way to clear NSLog output using code or not?
Like we have clrscr() in c. So if we are trying to print something which we want to focus most and there is lots of log printin there we can put that code there and get keep our desire log on top for easy searching. This can be done by putting breakpoint on my NSLog line and than click on clear console. but question is is there a way to achive this programatically?
I found few question on stack overflow but I din't satisfied with answer like this is saying that I can disable log for release mode etc.
Or I can use DLog, ALog or ULog as requirement but my question is different..
Any one can help me in this?
Thanks in advance :)
You can use a conditional breakpoint to simulate it. Define a function like this in your code:
int clear_console()
{
NSLog(#"\n\n\n\n\n\n\n\n");
}
Then, when you want to clear the console just add a breakpoint before the NSLog with this condition:
Condition: 1 > 0
Action: Debugger Command expr (int) clear_console()
Options: Automatically continue after evaluating Check it to skip the pause.
Tested with Xcode 4.3.2 and lldb.
Previous answer:
AFAIK, no, there isn't.
Just in case you're not doing it yet, you can create custom macros to format the output to highlight what you want.
Define macros like this:
#define CLEAR(...) NSLog(#"\n\n\n\n\n\n") /* enough \n to "clear" the console */
#define WTF(...) CLEAR();NSLog(#"!!!!!!!!!!!!!!");NSLog(__VA_ARGS__)
#define TRACE(__message__) NSLog(#">>>>>>>>>>>>>>> %# <<<<<<<<<<<<<<<<<<<", __message__)
Then:
WTF(#"This should't be here object: %#", theObject);
...
TRACE(#"Start Encoding");
...
It's not what you want but it pretty much solves the problem. You'll end up with your own set of macros with custom prefixes easily scannable in the console output.

AudioSessionInitialize returning inscrutable error code

I'm calling AudioSessionInitialize like so
OSStatus result = AudioSessionInitialize(NULL,NULL,interruptionListener,NULL);
and getting the result 0xbfffde94 (i.e. -1073750040) which doesn't match anything in the documentation, which are all readable 4CC's like '!ini' and so forth.
The good news is that it seems like the call worked. Nevertheless, can anyone shed light on this error code?
EDIT: The above error code is returned in the simulator. On the device the error code is 2fffe810.
Since these results are bogus and not defined or described by Apple, I am left with only but one assumption; you have a weird mix of Frameworks installed - possibly old versions mixed with newer ones. So all I could recommend is to reinstall the entire iPhone SDK.
I figured it out. I'm an idiot. There was an error in the macro I had wrapping the call & reporting the error, which called the AudioSessionInitialize twice. That doesn't quite explain the error code I saw, but it sure isn't worth wondering about.
UPDATE: Actually this is pretty slapstick so I'm going to explain.
The offending macro was originally:
#define CHECK(S) { OSStatus err = (S); if (S) printf("Error %x at \"%s\"\n", err, #S);}
so bug #1 is the if (S) which should be if if (err). Hence I'm repeating every call to the audio system, which explains various other weird things, so I'm very happy I tried to figure out what had seemed like a harmless anomaly. In this case the second call complained that the audio session was already initialized.
But why the weird error code? I wanted to see the 4CC's so I changed the macro to this, carrying the error along:
#define CHECK(S) { OSStatus err[2] = {S,0}; if (S) printf("Error %x '%4s' at \"%s\"\n", err, &err, #S); }
(The second OSStatus of 0 terminates the string defined by the 4CC first OSStatus, so I can print it with format %s.) But I forgot to change err to err[0], so it was indeed printing the address of the err array. This I'm pretty sure is correct now:
#define CHECK(S) { OSStatus err[2] = {S,0}; if (*err) printf("Error %x '%4s' at \"%s\"\n", *err, err, #S); }
Look at the OSStatus variable in the debugger's list of variables (lower left). Right click on it and select View Value As->Bytes (Hex with ASCII). Read the 4-letter code backwards.* This should match one of the documented result codes.
A value of 1768843636 is 74 69 6e 69 when viewed this way. Next to that the debug window shows 'tini'. Turn that around and you get 'init', which the documentation says is kAudioSessionAlreadyInitialized.
*No, I don't know why.