Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I am trying to debug a Perl Script, which uses the Text Balance extract bracketed function on some text that is enclosed in curly braces.
Unfortunately, the function returns nothing, not in the extracted or the remainder and there is error.
Is there a way where I can find out there reason for its failure? Is it possible for it to throw an exception saying for example, not able to extract because of the data structure. At the moment without knowing why, I can't really solve the problem.
See the Diagnostics section of the doc.
In addition, on failure in any context, the $# variable is set. Accessing $#->{error} returns one of the error diagnostics listed below. Accessing $#->{pos} returns the offset into the original string at which the error was detected (although not necessarily where it occurred!) Printing $# directly produces the error message, with the offset appended. On success, the $# variable is guaranteed to be undef.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
i'm looking to find a way to beautify my code in MATLAB. I'm talking about tabs, deleting unnecessary spaces etc., the way Eclipse does it with Ctrl+Shift+F
The smart indentation (ctrl + I) is probably all you need (as #Matteo V and #Cris Luengo already mentioned).
However, there are a few other neat tricks that you might want to have a look at if you are really into code development:
Well, first have a look at the Improve Code Readability site of MATLAB. You could use the Apply smart indenting while typing option in the Preferences > MATLAB > Editor/Debugger > Language > Indenting section (it should be turned on per default but I like the Indent all functions setting). There are a bunch of other settings that you may want to explore
If you dig yourself deeper in the MATLAB IDE, you will notice that you can adjust almost everything to your preferences, but the way is not always documented in the web.... however, the local documentation (call doc) contains the info you may be looking for, see this blog-post
I am not aware of an automatic detection of double spaces or similar but you might end up writing your own little callback-function. Most languages ignore this anyway (perhaps except for Python). Code readability is usually a topic that the programmer(s) should care about... and not the machines ;)
Further tips:
respect the Right-hand text limit, which is the vertical gray line in your editor and shall indicate how many characters a single line of code should have as maximum. If it is a comment, wrap it. If it is an expression, try to outsource some commands to a dedicated variable
use equally long variable names. (There is no style guide as in Python, which says that you should use normal words and underscores etc) E.g. if you have two variables describing a commanded and a measured velocity, you could call them v_cmd and v_act and your code perfectly aligns if you apply the same manipulations to both variables ;)
use section. With %% (the space is important) at the beginning of a line in the editor, you create a section (you'll note the slight yellow background color and the bold writing that follows this command). It is convenient to structure your code. You can even run entire sections Editor-Tab > Run > Run section
Although there are programmers claiming that a good code speaks for itself (and therefore doesn't need any comments), to my experience writing comments has never been a bad idea. It improves the readability of your code
The answer might have been a bit elaborate for such an innocent question ... oO
This question already has answers here:
When should I use semicolons in SQL Server?
(13 answers)
Closed 8 years ago.
Hello People more knowledgeable than me,
I'm taking some online courses for SQL and I am curious about something. With some instructors they draft script and don't seem to be concerned about ending simple commands with a ; however, other instructors seem to religiously add the semicolon at all times.
I'm just wondering, how important is the semicolon, should it be something that is always part of your script or does it not matter?
I know it's a pretty simple question, but the intro classes don't really define exactly why it's needed and since I'm seeing it used differently... I just want to make sure I understand.
Thank you!
Terminating semi-colons will be required in some future version of SQL Server.
Although it's not currently required, it's not a bad habit to get into.
As far as I know, I neglect semi-colons all too much, and my scripts nearly never break. So my best guess is no.
Still makes the code more readable since you do add a layer of seperation in your code.
Oh, you must use them at CTEs though which aren't first in batch
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
Some of my perl statements are executed even after commenting. I tried all the delimiter #, /*..*/, //
Does anyone face the same issue or can anyone help me how to solve this issue?
Your question appears to be "How do I create a comment in Perl?"
perlsyn says thusly:
Text from a "#" character until the end of the line is a comment, and is ignored. Exceptions include "#" inside a string or regular expression.
For example,
print "apple\n"; # Keeps the doctor away.
Keep in mind that comments can only be used where whitespace is expected. For example, the following does not contain any comments since the # is part of the string literal.
print "apple # Keeps the doctor away.
orange
";
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I've got some perl code (about 300-500 lines) that I've got to get working again. I've got limited experience programming, and normally if I'm coding I just find the best solution that make sense to me as is. In this case, I've got to use this code because it's built for an existing legacy system, for which the code is the documentation for the wiring, logic and rendering of the system. It's not a lot of code, but I also can't post even chunks of code or data to get help. What's the best method of understanding the syntax, what it's doing, how the code is wired, how the logic is model, etc.
Questions, feedback, comments -- just comment, thanks!!
See the book
Perl Medic, Transforming Legacy Code, by Peter Scott, from 2004.
A few review notes, including a table of contents, are listed at this perlmonks node.
A brief review is here.
The book covers many techniques in enough depth to learn & apply them to your problem. If you only have a little time, scan the whole book, then I recommend Chapter 3 on testing, Chapter 4 on rewriting, and Chapter 11, A Case Study (30+ pages).
If you don't use this book, at least use perldoc to learn Test::More and related modules. Having useful tests that exercise the original and modified code will build your confidence in making changes, because you can see when a specific change causes a test to fail.
Update.
See this book for more detailed data on Perl's test tools than given in Perl Medic:
Perl Testing: A Developer's Notebook, by Ian Langworth & chromatic, 2006.
Some time ago I read nice text about understanding large project quickly on perlmonks - Swallowing an elephant in 10 easy steps. There are many useful suggestions that can pay off.
Have a look for tools like perltidy which will regularize the formatting.
Also consider running the code in the debugger, and stepping through line by line. See perldoc perldebug for details.
My advice would be to start with the functions... go through the code, find everywhere a function is used and determine if it is a regular perl function that is universal, or if it is a custom function. Then search the code and find where all of the custom functions are created and determine what each individual function does.
Add comments to the code as you go, once you figure out what a function is doing, add a comment.
That alone should give you a good head start.
In more nitty gritty, you may want to go through after that and label/comment/make note of what each perl variable is used for/what it is the first time it is used.
That should get you well on your way to figuring the code out... and if there is a function or something else you can't figure out, search the web using the wonderful Google... or post here not necessarily with the exact code, as you said you can't, but with a general idea of what it is doing.
Also, one thing I forgot to mention, is to find any loops, whether while, for, etc and determine what is running inside of them and what they are being looped through.
There have been some good suggestions already, another one is the B::Deparse module, which attempts to rewrite your code (often) in a longer clearer way.
For example when you run perl -MO=Deparse ob.pl on the file ob.pl containing this obfuscated code:
#P=split//,".URRUU\c8R";#d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
#p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
You get:
#P = split(??, '.URRUUxR', 0);
#d = split(??, "\nrekcah xinU / lreP rehtona tsuJ", 0);
sub p {
#p{"r$p", "u$p"} = ('P', 'P');
pipe "r$p", "u$p";
++$p;
($q *= 2) += $f = !fork;
map {$P = $P[$f ^ ord $p{$_} & 6];
$p{$_} = / ^$P/xi ? $P : close $_;} keys %p;
}
p ;
p ;
p ;
p ;
p ;
map {close $_ if $p{$_} =~ /^[P.]/;} %p;
wait until $?;
map {<$_> if /^r/;} %p;
$_ = $d[$q];
sleep rand 2 if /\S/;
print $_;
ob.pl syntax OK
Which is (possibly) better; I don't know, maybe not. Worth a try anyway.
Edit: you can get even a little more info by changing the command to perl -MO=Deparse,-p ob.pl which puts in explicit parentheses which can help understand operator precedence.
Aren't there any comments in the program that can let you know what each line or each function is doing?
I would go through the code from start to finish. Using a pen and lots of paper. This were the author of the program should have written test cases, so that new programmers, like yourself, can understand how the code works. Not many programmers write test cases.