ZSH function not working with a "Missing end of string" error - error-handling

I'm teaching myself to write zsh functions and I'm stumped right away with a string error I don't understand. I have this function:
function copyToDrafts() {
print($1)
}
in my command line editor (Terminal) I type:
copyToDrafts "test"
and receive this error:
copyToDrafts:1: missing end of string
I couldn't find any explanation on the error message and can't see anything wrong with what I am passing, though obviously something is wrong. Any help would be appreciated.

The parentheses are not part of the syntax; they are interpreted as introducing a glob qualifier on the pattern print. After parameter expansion, the pattern to be evaluated is
print(test)
with the following glob qualifiers:
t - match files named print that have their sticky bits set
e execute a shell command. s acts as the delimiter, but there is no "closing" s, which produces the observed error.
You simply need to drop the parentheses.
copyToDrafts () {
print $1
}

Related

Parse error: syntax error, unexpected '"', expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:... on line 22

I want to update a row in a table for my project, I'm copying a syntax I saw somewhere else here however, I think my problem comes when I try updating where ApplicantID is equal to $_SESSION["ID"].
I get this error
Parse error: syntax error, unexpected '"', expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\xampp\...\InsertPData.php on line 22
here is the php along side the SQL:
<?php
include_once'dbconnect.php';
session_start();
function INSERT()
{
$Name=$_POST['name'];
$Relation=$_POST['Relation'];
$Email=$_POST['Email'];
$Address=$_POST['Address'];
$Postcode=$_POST['Postcode'];
$Mobile_Number=$_POST['Mobile_Number'];
$Home_Number=$_POST['Home_Number'];
$INSERT="UPDATE Applicants
SET ParentName='$Name',
Relationtoapplicant='$Relation',
ParentEmail='$Email',
ParentAddress='$Address',
ParentPostcode='$Postcode',
ParentMobile='$Mobile_Number',
ParentHome='$Home_Number',
WHERE ApplicantID=$_SESSION["ID"] "; #THIS IS LINE 22
$data=mysql_query($INSERT) or die(mysql_error());
if($data)
{
echo "Parents/Gauridan details hav been entered";
}
else print "error";
}
INSERT()
?>
I've already searched for a solution to this but haven't found something where the user is using a session thing. Thank you.
This is why an IDE with syntax highlighting is helpful. StackOverflow uses syntax highlighting on code blocks as well and actually already gives you the answer based on your code:
$INSERT="UPDATE Applicants
WHERE ApplicantID=$_SESSION["ID"] ";
See how ID is suddenly black instead of dark red? That's because you are terminating the string there. The double quotes should either be escaped or replaced with single quotes, like:
$INSERT="UPDATE Applicants
WHERE ApplicantID=$_SESSION[\"ID\"] ";
Or
$INSERT="UPDATE Applicants
WHERE ApplicantID=$_SESSION['ID'] ";
See how the ID bit stays dark red? This is because now your string is not suddenly terminated.
Also, please do not use mysql_ functions anymore. They have been deprecated since 2013 and are currently not even a part of PHP anymore. So if you'd update your PHP to the latest version, this code would not work. On top of that, this code is vulnerable to SQL injection attacks.
Also see Why shouldn't I use mysql_* functions in PHP? and How can I prevent SQL-injection in PHP?.

Parsing an error string in Lua

Lets say I have the following error string:
err = "/mnt/cd4/autorun.lua:43: 'end' expected (to close 'while' at line 1)
near '-eof-'"
How would I parse the file path, line number, and the error message separately from the string?
I have no prior experience in parsing Lua strings, so I thought asking here would be useful. I also tried finding a topic solving the same matter but I could not find one.
Something like this should work:
err = "/mnt/cd4/autorun.lua:43: 'end' expected (to close 'while' at line 1) near '-eof-'"
local file, line, errmsg = err:match('^(.-):(%d+):(.+)')
print(file, line, errmsg)
The pattern says: capture starting at the end of the line (^) a shortest group of zero or more (-) of any symbol (.), followed by :, then a group of one or more digits (%d+), followed by :, and then a group of one of more symbols (.+). You can read about patterns here.

Comma, ')',or valid expression continuation expected

I need my VB.net to write a file containing the following line
objWriter.WriteLine ("TEXTA " (FILEA) " TEXTB")
Unfortunatly the variable (FILEA) is causing problems i now get the error
Comma, ')', or valid expression continuation expected.
Could someone explain this please?
You're not concatenating (joining) the strings proerly...
objWriter.WriteLine ("TEXTA " & FILEA & " TEXTB")
A better style to get into the habit of using is:
objWriter.WriteLine (string.format("TEXTA {0} TEXTB", FILEA))
The FILEA variable replaces the {0} placeholder in the format string. Depending on what the writer you're using is, you may have a formatted overload so you could just do:
objWriter.WriteLine ("TEXTA {0} TEXTB", FILEA)
And since you asked for an explanation;
The compiler is asking you what exactly you want it to do - you've given it 3 variables (String, variable, String) and haven't told it that you want to join them together - It's saying that after the first string "TEXTA", there should either be the closing bracket (to end the method call), a comma (to pass another parameter to the method) OR a "valid continuation expression" - ie something that tells it what to do with the next bit. in this case, you want a continuation expression, specifically an ampersand to signify "concatenate with the next 'thing'".
Presumably you're looking for string concatenation? Try this:
objWriter.WriteLine("TEXTA" & FILEA & "TEXTB");
Note that FILEA isn't exactly a conventional variable name... which leads me to suspect there may be something else you're trying to achieve. Could you give more details?

why does using "\" shows error in jython

I am trying to use a copy command for Windows and we have directories such as c:\oracle.
While trying to execute one such, we get the following error:
source_file=folder+"\"
^
SyntaxError: Lexical error at line 17, column 23. Encountered: "\r" (13), after : ""
Here folder is my path of c:\oracle and while trying to add file to it like:
source=folder+"\"+src_file
I am not able to do so. Any suggestion on how to solve this issue?
I tried with / but my copy windows calling source in os.command is getting "the syntax is incorrect" and the only way to solve it is to use \ but I am getting the above error in doing so.
Please suggest. Thanks for your help
Thanks.
Short answer:
You need:
source_file = folder + "\\" + src_file
Long answer:
The problem with
source_file = folder + "\" + src_file
is that \ is the escape character. What it's doing in this particular case is escaping the " so that it's treated as a character of the string rather than the string terminator, similar to:
source_file = folder + "X + src_file
which would have the same problem.
In other words, you're trying to construct a string consisting of ", some other text and the end of line (\r, the carriage return character). That's where your error is coming from:
Encountered: "\r" (13)
Paxdiablo is absolutely correct about why \ isn't working for you. However, you could also solve your problem by using os.path.normpath instead of trying to construct the proper platform-specific path characters yourself.
In all programming languages I know of, you can't put a quote inside a string like this: "this is a quote: "." The reason for this is that the first quote opens the string, the second then closes it (!), and then the third one opens another string - with the following two problems:
whatever is between the quotes #2 and #3 is probably not valid code;
the quote #3 is probably not being closed.
There are two common mechanisms of solving this: doubling and escaping. Escaping is far more common, and what it means is you put a special character (usually \) in front of characters that you don't want to be interpreted in their usual value. Thus, "no, *this* is a quote: \"." is a proper string, where the quote #2 is not closing the string - and the character \ does not appear.
However, now you have another problem - how do you actually make the escape character appear in a string? Simple: escape it! "This is an escape: \\!" is how you do it: the backslash #1 is the escape character, and the backslash #2 is the escapee: it will not be interpreted with its usual escape semantics, but as a simple backslash character.
Thus, your line should say this:
source=folder+"\\"+src_file
BTW: upvote for both #paxdiablo (who got in before my diatribe) and #Nick (who has a proper Pythonic way to do what you want to do)

get in Object 'Func with Refinement in Rebol

Let's say I have
o: context [
f: func[message /refine message2][
print [message]
if refine [print message 2]
]
]
I can call it like this
do get in o 'f "hello"
But how can I do for the refinement ? something like this that would work
>> do get in o 'f/refine "hello" "world"
** Script Error: in expected word argument of type: any-word
** Near: do get in o 'f/refine
>>
I don't know if there's a way to directly tell the interpreter to use a refinement in invoking a function value. That would require some parameterization of do when its argument is a function! Nothing like that seems to exist...but maybe it's hidden somewhere else.
The only way I know to use a refinement is with a path. To make it clear, I'll first use a temporary word:
>> fword: get in o 'f
>> do compose [(to-path [fword refine]) "hello" "world"]
hello
world
What that second statement evaluates to after the compose is:
do [fword/refine "hello" "world"]
You can actually put function values into paths too. It gets rid of the need for the intermediary:
>> do compose [(to-path compose [(get in o 'f) refine]) "hello" "world"]
hello
world
P.S. you have an extra space between message and 2 above, where it should just be message2
Do this:
o/('f)/refine "hello" "world"
Parens in a path expression are evaluated if they correspond to object field or series pick/poke index references. That makes the above code equivalent to this:
apply get in o 'f ["hello" true "world"]
Note that apply arguments are positional, so you need to know the order the arguments were declared in. You can't do that trick with the function refinements themselves, so you have to use apply or create path expressions to evaluate if you want to parameterize the refinements of the function call.
Use the simple path o/f/refine