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 5 months ago.
Improve this question
Page 109 of The AWK Programming Language book has a statement to create a 2-D array named attr:
attr[nrel, $1] = ++nattr[nrel]
nrel = an integer representing the number of relations (tables)
nattr = an integer representing the number of attributes (table columns)
Substituting country for $1, 1 for nrel, and 1 for nattr we have:
attr[1, country] = 1[1]
What does the right-hand side of that statement mean? It appears to be referencing subscript 1 of array 1. Can an array be named 1? Would you explain what that expression means, please?
Page 109(...)
I have look into archive.org's version and line
attr[nrel, $1] = ++nattr[nrel]
is sole line referencing nattr and therefore this is where nattr is created, as you are asking about value under key it will be array. You might check that by substituting all but nattr as proposed and using typeof function
awk 'BEGIN{attr[1, "France"] = ++nattr[1];print typeof(nattr)}' emptyfile
gives output
array
therefore shown line does firstly increase value in array nattr under key nrel and then assign such changed value to array attr under key nrel, $1.
(tested in gawk 4.2.1)
Related
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 have a dataframe which looks as following:
df['col1'].values
array(['cat 113kd29', 'do56goat24kdasd', 'pig145kd'])
I need to create a new column df['vals'] with following values:
cat 29
do56goatasd
pig
i.e. first I need to look for substring kd and then find the numeric value preceding it. I am not sure how to go about this.
There can be multiple numeric values in each string so I need to find only ones before kd. Please note the string 'cat 113kd29'. Also look at 'do56goat24kdasd'
I tried the following but it didn't work:
df['col1'].str.replace(r'(\d+)kd', '')
Your call to str.replace is correct, but you need to assign it to the original Pandas column on the left hand side of an assignment:
df["col1"] = df["col1"].str.replace(r'\d+kd', '')
Note that str.replace does a global replacement by default, so there is no need to use any sort of flag.
Another way is to match digits precedingkd and kd and replace it with nothing
df["col1"]=df.col1.str.replace('\d+kd\Z','', regex=True)
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 1 year ago.
Improve this question
My code:
fun main() {
println("What's your name?")
val name= readLine()
println("Hello $name")
}
Output:
What's your name?
Abhas
Hello
My question is: Why $name is not getting printed? After taking input ' Abhas ' it doesn't show anything and then after I pressed Enter and it prints ' Hello ' only.
I'm not sure why it's not working for you - it is reading some input or it wouldn't get to the println statement, and it is printing the value of name (which has a value, otherwise it would say null).
At a guess, it's something to do with the way you're providing input, where the first line it reads is empty, so you get an empty string (""). You said your output is like this:
What's your name?
Abhas
Hello
Are you hitting enter/return to get to the next line before you type Abhas? That does nothing in the REPL I'm using, but it might count as an (empty) input line in your console
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 2 years ago.
Improve this question
I want to migrate the data to a target table.
However, I want to make a reject file for null values and values whose size exceeds 20 characters. As I do with Conditional Splitting?
I did that but it doesn't work:
"if len(mail)>10 caractère"
i will export this values to reject file
How can i do this Please ?
Design
You can do this directly in a conditional split but I advise against doing so. Instead, compute the boolean (true/false) condition in a Derived Column and add that to your data flow. Then, if you get unexpected results, you can add a data viewer between the Derived Column step and the Conditional Split
Implementation
Add a Derived Column to the data flow. Add a new column called BadMail. If it's true, then we'll route to the bad file. If it's true, it will proceed to the destination.
The Expression language for SSIS will use the ternary operator (test) ? true_condition : false_condition
I am going to test for null ISNULL(mail), longer than 20 len(mail) > 20 and zero length len(mail) == 0.
The || is a logical or so if any of those three conditions are true, then we need to set the BadMail to true
(ISNULL(mail) || len(mail) > 20 || len(mail) == 0) ? true : false
You could simplify that to eliminate the ternary operator but I find being explicit in my intentions helpful in these situations. As a side note, if you are still having issues with unexpected results, add a preceding Derived Column transformation and add a column in for each criteria (null, 0 or greater than 20 character) and then you can inspect them individually.
Now, we add the Conditional Split
The expression here is just our new column BadMail and that will route to Output Path 1 or whatever you name it. The good mail will pass through to the default output path.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
As far I as my experience tells me, boolean variables usually named in format - is/has+noun/adj/verb, e.g isValid, isButton, hasClickedLink
But say there is the case where we have some flag which straightly tells whether to do something, like for example, clean to indicate that cleanup function should be automatically called in the end.
How to name such a booleans? Same clean - is ambiguous, looks like a method name more, but naming it toClean is, I don't know, too weird. Or should I name it like callCleanup?
Thanks in advance!
In this case i usually append the word wanted, which makes cleanWanted. In general, for boolean variables I also prefer to always let the last word be an adjective. This makes it very clear that it represents a truth value. The is/has prefix is often superfluous, as in hasClickedLink which is more concisely communicated with linkClicked.
methods are usually one word adjectives with a capitol at the start
maybe create a method that sets the flag
for example
void Clean(){
clean = True;
}
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Which computer languages will allow code that dynamically extracts a variable name from a string, like user types in an argument "hhh", and the code then knows to reference a variable with the identifier: hhh? Thanks for your help.
Not exactly "dynamic variable creation", but you can get pretty much the same effect by using an associative array (a.k.a. dictionary or map). For example, in Python:
vars = {}
vars['x'] = 'hello'
vars['y'] = 10
With the above code, the keys 'x' and 'y' in the dictionary are like dynamic variables for all practical purposes, for example:
print vars['x']
> hello
vars['y'] + 6
> 16
As a matter of fact, under the hood many programming languages (Python, JavaScript, etc.) use a dictionary of bindings for implementing variables and scoping rules.
The associative array is probably a better idea to use, but just in case, php supports this without putting the code inside an eval function:
<?php
class ff {
var $u = "aagg";
}
$y = new ff();
$i = "u";
echo $y->$i;
?>