Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
(The Script)
#!/usr/bin/perl
# Program, named literals.perl
written to test special literals
1 print "We are on line number ", _ _LINE_ _, ".\n";
2 print "The name of this file is ",_ _FILE_ _,".\n";
3 _ _END_ _
And this stuff is just a bunch of chitter–chatter that is to be
ignored by Perl. The _ _END_ _ literal is like Ctrl–d or \004.[a]
(Output)
1 We are on line number 3.
2 The name of this file is literals.perl.
Explanation
The special literal _ _LINE_ _ cannot be enclosed in quotes if it is to be interpreted. It holds the current line number of the Perl script.
The name of this script is literals.perl. The special literal _ _FILE_ _ holds the name of the current Perl script.
The special literal _ _END_ _ represents the logical end of the script. It tells Perl to ignore any characters that follow it.
print "The script is called", _ _FILE_ _, "and we are on line number ",
_ _LINE_ _,"\n";
(Output)
The script is called ./testing.plx and we are on line number 2
I need help getting this example to work. I am having a bit of trouble running it. when i run it on console2 i would get an error stating this
"cant locate object method "_" via package "LINE" (perhaps you
forgot to load "LINE"?) at C:\users\john\desktop\console2\test.pl
line 5.
Any ideas on how to fix this would be most appreciated. Thanks!
You need to use names without spaces between the underscores:
#!/usr/bin/env perl
use strict;
use warnings;
print "We are on line number ", __LINE__, ".\n";
print "The name of this file is ", __FILE__, ".\n";
__END__
print "This is not part of the script\n";
When saved in fileline.pl and run, this produces:
We are on line number 5.
The name of this file is fileline.pl.
Note that there are no spaces between the consecutive underscores. And note that the final line containing a print statement is not part of the script because it comes after the __END__. (There's also a __DATA__ directive that can sometimes be useful.)
There's no space in the literals __FILE__ and __LINE__ (or __END__). Just 2 underscores in a row, the word, and another 2 underscores.
Related
I can split a string with strings.Split:
strings.Split(`Hello World`, " ")
// ["Hello", "World"] (length 2)
But I'd like to preserve backslash escaped spaces:
escapePreservingSplit(`Hello\ World`, " ")
// ["Hello\ World"] (length 1)
What's the recommended way to accomplish this in Go?
Since go does not support look arounds, this problem is not straightforward to solve.
This gets you close, but leaves a the trailing space intact:
re := regexp.MustCompile(`.*?[^\\]( |$)`)
split := re.FindAllString(`Hello Cruel\ World Pizza`, -1)
fmt.Printf("%#v", split)
Output:
[]string{"Hello ", "Cruel\\ World ", "Pizza"}
You could then trim all the strings in a following step.
I am trying to do an if statement where it finds all the observations in the column "CarBrands" that have an underscore _ in the string (it's a character), and if it has the _, then I want to remove it. How do I do this? Thanks.
You can use the FIND function to check if a string contains the underscore. Then with the COMPRESS function, you can remove the underscore.
For example;
data work.ds;
input mystring $;
datalines;
mytext
my_text
;
run;
data work.ds_1;
set work.ds;
if find(mystring,'_') > 0 then mystring = compress(mystring,'_');
else mystring = mystring;
run;
See also:
https://sasexamplecode.com/find-a-substring-in-sas/
https://documentation.sas.com/?docsetId=lefunctionsref&docsetTarget=n0fcshr0ir3h73n1b845c4aq58hz.htm&docsetVersion=9.4&locale=en
I am reading a command line string from a config file (config.json) :
"execmd" : "c:\\windows\\system32\\cmd.exe /c runscript.cmd"
I want to pass this to exec.Command() - but this function requires 2 parameters:
exec.Comm*emphasized text*and (cmd, args...)
Where cmd is the first segment (cmd.exe) and args would then be every space deliminated value thereafter.
I am not exactly sure if I need to read the config string, and then manually split it up in an array for each space deliminator? Is there any way of converting a string into args easily?
How would it be possible to do something like this, where I can refer args... from an index? (the below code doesn't work, can't refer args this way)
exec.Command (arg[0], args[1]...)
If the values coming it from the config file are in a format executable by shell, you're going to run into a host of problems just splitting on spaces (e.g. quoted arguments containing spaces). If you want to take in a command line that would be executable in a shell, you're going to want to have a shell execute it:
exec.Command("cmd.exe", "/c", execmd)
There is no way of "converting a string into args" because it varies from shell to shell.
I found this thread regarding the issue : https://groups.google.com/forum/#!topic/golang-nuts/pNwqLyfl2co
Edit 1: ( didnt work )
And saw this one using RegExp - and found out how i can index into the args also :
r := regexp.MustCompile("'.+'|\".+\"|\\S+")
s := appConfig.JobExec.ExecProcess
m := r.FindAllString(s, -1)
Exec.Command (m[0],m[1:])
This seems to work also with quoted strings !
Edit 2:
It didnt work and didnt work on windows, theres an issue with params being passed on when running with cmd. Using sysprocattr.cmdline will make it work :
cmdins := exec.Command(cmd)
cmdins.SysProcAttr = &syscall.SysProcAttr{}
for _, arg := range args {
cmdins.SysProcAttr.CmdLine = cmdins.SysProcAttr.CmdLine + arg + " "
}
the issue described here :
https://github.com/golang/go/issues/17149
I have an issue in one of my functions in my code. I am new to Ruby, so I am unsure of where my syntax error is. My irb is giving me a syntax error related to my end keywords, but I believe the syntax is correct
def function1
print "function 1 \n"
print "Please type 4 lines \n"
i = 0
fptr = (File.new("myFile.txt", "w"))
while i < 4
line = gets
fptr.write(line "\n")
i++
end
fptr.close()
end
This function should print two output lines, open a txt file, take in 4 lines of user input, and write them to the said file.
The problem is that i++ is not valid Ruby. Use i += 1 instead.
I would like to get a working code to simply remove from a text line a specific part that always begins with "(" and finish with ")".
Sample text : Hello, how are you (it is a question)
I want to remove this part: "(it is a question)" to only keep this message "Hello, how are you"
Lost...
Thanks
One way using Regular Expressions;
input = "Hello, how are you (it is a question)"
dim re: set re = new regexp
with re
.pattern = "\(.*\)\s?" '//anything between () and if present 1 following whitespace
.global = true
input = re.Replace(input, "")
end with
msgbox input
If the part to be removed is always at the end of the string, string operations would work as well:
msg = "Hello, how are you (it is a question)"
pos = InStr(msg, "(")
If pos > 0 Then WScript.Echo Trim(Left(msg, pos-1))
If the sentence always ends with the ( ) section, use the split function:
line = "Hello, how are you (it is a question)"
splitter = split(line,"(") 'splitting the line into 2 sections, using ( as the divider
endStr = splitter(0) 'first section is index 0
MsgBox endStr 'Hello, how are you
If it is in the middle of the sentence, use the split function twice:
line = "Hello, how are you (it is a question) and further on"
splitter = split(line,"(")
strFirst = splitter(0) 'Hello, how are you
splitter1 = split(line,")")
strSecond = splitter1(UBound(Splitter1)) 'and further on
MsgBox strFirst & strSecond 'Hello, how are you and further on
If there is only one instance of "( )" then you could use a '1' in place of the UBound.
Multiple instances I would split the sentence and then break down each section containing the "( )" and concatenate the final sentence.