crystal Error: undefined method 'length' for Array(String) - crystal-lang

converting something from ruby to crystal
$ cat test.cr
puts ARGV.length
works in ruby, but crystal
$ crystal test.cr
Showing last frame. Use --error-trace for full trace.
error in line 1
Error: undefined method 'length' for Array(String)

appears the correct method is "size". crystal doesn't have as many aliases, to standardize.
$ cat test.cr
puts ARGV.size
$ crystal test.cr 1 2 3
3

Related

Compare two files and extract line based on matching substring?

I have two files
crackedHashes.txt formatted as Hash:Password
C3B9FE4E0751FC204C29183910DB9EB4:fretful
CA022093C4BAFA397FAC5FB2E407FCA9:remarkable
36E13152AA93A7631608CD9DD753BD2A:please
hashList.txt formatted as Username:Hash
Frank:C3B9FE4E0751FC204C29183910DB9EB4
Jane:A67BC194586C11FD2F6672DE631A28E0
Lisa:CA022093C4BAFA397FAC5FB2E407FCA9
John:36E13152AA93A7631608CD9DD753BD2A
Dave:6606866DB8B0232B371C2C4C35B37D01
I want a new file that combines the two lists based on the same matching hash.
output.txt
Frank:C3B9FE4E0751FC204C29183910DB9EB4:fretful
Lisa:CA022093C4BAFA397FAC5FB2E407FCA9:remarkable
John:36E13152AA93A7631608CD9DD753BD2A:please
I've been scouring the forums here and can only find things returning one string or not using regex (matching whole line). I've tried to do it in parts so I first broke up crackedHashes by doing sed 's/:.*//' crackedHashes.txt and then was going to do the same for the other file and compare by basically writting a bunch of outfiles and comparing the outfiles. I also tried comparing based on variation of grep -f crackedHashes.txt hashList.txt > outfile.txt but that was yielding many more "results" than it was supposed to.
I could manually do grep <hash> hashList.txt> but when it comes to files and lines I'm a bit lost
With GNU join, bash and GNU sort:
join -1 1 -2 2 -t : <(sort crackedHashes.txt) <(sort -t : -k 2 hashList.txt) -o 2.1,1.1,1.2
Output:
John:36E13152AA93A7631608CD9DD753BD2A:please
Frank:C3B9FE4E0751FC204C29183910DB9EB4:fretful
Lisa:CA022093C4BAFA397FAC5FB2E407FCA9:remarkable
See: man join

Why don't `csplit` and `grep` agree on whether there are matches?

I am trying to use csplit in BASH to separate a file by years in the 1500-1600's as delimiters.
When I do the command
csplit Shakespeare.txt '/1[56]../' '{36}'
it almost works, except for at least two issues:
This outputs 38 files, not 36, numbered xx00 through xx37. (Also xx00 is completely blank.) I don't understand how this is possible.
One of the files (why, it seems, that csplit returns 37 non-empty files instead of the 36 non-empty files I expected) doesn't begin with 15XX or 16XX -- it begins with "ACT 4 SCENE 15\n" (where \n is supposed to denote a newline or line break). I don't understand how csplit can match a new line/line break with a number.
When I do the command (which is what I want)
csplit Shakespeare.txt '/1[56][0-9][0-9]/' '{36}'
the terminal returns the error: csplit: 1[56][0-9][0-9]: no match plus listing all of the numbers it lists when the above is executed.
This especially doesn't make sense to me, since grep says otherwise:
grep -c "1[56][0-9][0-9]" Shakespeare.txt
36
grep -c "1[56].." Shakespeare.txt
36
Note: man csplit indicates that I have the BSD version from January 26, 2005. man grep indicates that I have the BSD version from July 28, 2010.
Based on the answer given here by user 'DRL' on 06-20-2008, I decided to try adding the -k option to csplit.
csplit -k Shakespeare.txt '/^1[56][0-9][0-9]/' '{36}'
This returned an error: csplit: ^1[56][0-9][0-9]: no match
However, it still gave (more or less) the desired output: files xx00.txt through xx36.txt (not xx37.txt), and each of the non-empty files, xx01.txt-xx36.txt had the expected/desired content. (In particular, no file began with "ACT 4 SCENE 15".
The man page for csplit says the following about the -k flag:
-k Do not remove output files if an error occurs or a HUP, INT or TERM signal is received.
Honestly I don't quite understand what this means, but I still have the following conjecture about why this solution worked/works:
Conjecture: csplit expects the beginning of the file to match the regex. Thus, since the beginning line of the file did not match ^1[56][0-9][0-9], it threw a tantrum and quit without the -k flag.
Nevertheless, I still don't understand why 1[56][0-9][0-9] did not work, maybe the same reason. And I definitely don't understand why 1[56].. did not work (i.e. why csplit produced a 37th file not beginning with the pattern).

How do I get Weka 3.6 and 3.7 to accept "-S" filter option for Stop word removal in Snowball stemmer from command line?

I have tried both Weka 3.6 and 3.7 but neither will accept the following command:
java weka.filters.unsupervised.attribute.StringToWordVector -N 0 -L –S -stemmer "weka.core.stemmers.SnowballStemmer" -M 5 -tokenizer "weka.core.tokenizers.NGramTokenizer -delimiters \W -min 1 -max 1" -i "inputfile.arff" -o "outputfile.arff"
The error message that is returned is
"
Illegal options: ?S
Filter options: -C -R -V -P -W ... -S ....
"
i.e. a list of valid filter options of which "-S" for stopword removal is listed as the means of implementing stop word removal.
I have already checked online weka documentation at
http://weka.sourceforge.net/doc.dev/weka/filters/unsupervised/attribute/StringToWordVector.html
which also specifies "-S" as a valid filter switch.
I can't see what I'm doing wrong. Can anybody help please?
Thanks.
There is something about your dash in the S parameter that looks a bit bigger than the others.
I did a copy and paste of this character and it also appears larger than the minus key. Perhaps try '-' instead.
My optometrist claims that I have 20/20 vision. Hopefully it has assisted in some way for the problem mentioned above.
Hope this helps!

Detecting errors of a command that print nothing if the command was successful using Perl and Expect

I am trying to automate the configuration of a server using perl and the expect module. I have been using the expect module three days but now I have encountered a problem that I can't solve.
My problem is when im executing a command that prints no output if it is successful but prints an error message if something went wrong. An example of such command is the cd command:
$ cd .
$
$ cd sadjksajdlaskd
sadjksajdlaskd: No such file or directory.
$
What I would like to do is to send the command to the server, and then perform an expect call to check if something other than the prompt sign was printed. Something like this:
$com->send("cd $dir");
$com->expect(2,
["^[^$#]*", sub {
my $self = shift;
my $error = $self->match();
die "ERROR: $error";
}],
"-re", "^[$#]"
);
The problem I have is that when I perform the expect call it will match against all previous text and not against text received after the send call, so it will always match and report an error. How do I make expect match only agains the text received after the send call? Is it possible to clear the buffer of the expect module or is it possible to achieve this kind of error detection some other way?
I also wonder how the expect module handles regular expressions. If I for example use "^[$#]\$" as the regular expression to match the prompt of the terminal, will the \$ part of the regular expression match end of line or an actual dollar sign? If i remove the \ perl complains.
Thanks in advance!
/Haso
EDIT: I have found a solution:
The solution was to use $com->clear_accum() which clears the accumelator. I have tried using it before but it seems like this function only works at random, or maybe I don't understand what clear_accum() is suppose to do.
EDIT: A final note about clear_accum():
The reason the clear_accum() function seems to work at random is because the text generated from the previous send is not read into the accumelator until an expect() call is made. So in order to truly clear all previous data is to first perform an expect() call and then clear the accumelator:
#To clear all previous data
$com->expect(0);
$com->clear_accum();
akarageo#Pal4op:~> cd banana
bash: cd: banana: No such file or directory
akarageo#Pal4op:~:( > echo $?
1
i.e. check the error code that CD returns, 0 means OK anything else is an error, No need to check the prompt , and btw, the CD command does not generate the prompt the shell does, so that must be part of your confusion also.
try $object->exitstatus() if it is of any help

have number of modified and unknown mercurial files on prompt

I'm using the hg prompt extension to have a nice prompt while working with hg.
Right now my prompt looks like this:
~/my/current/path [hg default !]
the '!' part in the prompt I get via the {status} keyword of the hg prompt showing me that are modified files. It shows a '?' for unknown files
But I want something similar to posh-hg where it also shows the number of modified or unknown files.
I know I can get this information with hg summary but my sed fu is failing me on getting the regex correct to get the totals.
an example of the output of the hg summary command:
parent: 0:16ed527e220f tip
parent commit message
branch: default
commit: 5 modified, 2 unknown
update: (current)
doing a hg summary | grep 'commit' I get back the correct line:
$ hg summary | grep 'commit'
commit: 5 modified, 2 unknown
given the output above, how can I get the number of modified and unknown files so that I can make my prompt look like this:
[hg default 5! 2?]
This works:
hg sum | sed -ne '/^commit:/{s/^commit: //;s/ modified/\!/;s/ unknown/?/;s/,//g;p}'
... although there might be a more elegant way to do it.
You can probably figure out the added, deleted etc part by yourself.