Pure Programmer
Blue Matrix


Cluster Map

Project: Reorder Columns

Write a program that reorders tab-delimited input provided on stdin. It should take commandline arguments that specify the columns to print. The order of the arguments determine the order that the columns are printed. The columns are numbered from one to the number of columns in the data.

Output
$ rustc ReorderColumns.rs error[E0432]: unresolved import `regex` --> ReorderColumns.rs:8:5 | 8 | use regex::Regex; | ^^^^^ maybe a missing crate `regex`? | = help: consider adding `extern crate regex` to use the `regex` crate error[E0425]: cannot find value `args` in this scope --> ReorderColumns.rs:28:5 | 28 | if args.len() < 2 { | ^^^^ not found in this scope | help: consider importing this function | 8 + use std::env::args; | error[E0425]: cannot find function `exit` in this scope --> ReorderColumns.rs:30:3 | 30 | exit(1); | ^^^^ not found in this scope | help: consider importing this function | 8 + use std::process::exit; | error[E0425]: cannot find value `args` in this scope --> ReorderColumns.rs:35:15 | 35 | while i <= (args.len() - 1) { | ^^^^ not found in this scope | help: consider importing this function | 8 + use std::env::args; | error[E0425]: cannot find value `Utils` in this scope --> ReorderColumns.rs:36:17 | 36 | colNums.push(Utils.stoiWithDefault(args[i], 0)); | ^^^^^ not found in this scope error[E0425]: cannot find value `args` in this scope --> ReorderColumns.rs:36:39 | 36 | colNums.push(Utils.stoiWithDefault(args[i], 0)); | ^^^^ not found in this scope | help: consider importing this function | 8 + use std::env::args; | error[E0425]: cannot find function `split` in this scope --> ReorderColumns.rs:11:27 | 11 | let fields:Vec<String> = split(line,Regex::new(r"\\t").unwrap()); | ^^^^^ not found in this scope error[E0308]: mismatched types --> ReorderColumns.rs:14:13 | 14 | while i < columns.len() { | - ^^^^^^^^^^^^^ expected `isize`, found `usize` | | | expected because this is `isize` | help: you can convert a `usize` to an `isize` and panic if the converted value doesn't fit | 14 | while i < columns.len().try_into().unwrap() { | ++++++++++++++++++++ error[E0277]: the type `[isize]` cannot be indexed by `isize` --> ReorderColumns.rs:18:15 | 18 | if columns[i] > 0 && columns[i] <= fields.len() { | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[isize]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<isize>` to implement `Index<isize>` error[E0277]: the type `[isize]` cannot be indexed by `isize` --> ReorderColumns.rs:18:33 | 18 | if columns[i] > 0 && columns[i] <= fields.len() { | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[isize]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<isize>` to implement `Index<isize>` error[E0277]: the type `[isize]` cannot be indexed by `isize` --> ReorderColumns.rs:19:33 | 19 | print!("{}", fields[columns[i] - 1]); | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[isize]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<isize>` to implement `Index<isize>` error[E0425]: cannot find function `getline` in this scope --> ReorderColumns.rs:42:8 | 42 | while getline(line) { | ^^^^^^^ not found in this scope error: aborting due to 12 previous errors Some errors have detailed explanations: E0277, E0308, E0425, E0432. For more information about an error, try `rustc --explain E0277`.

Solution