var verbose = flag.Bool("v", false, "verbose")
flag.Parse()
fmt.Println("verbose is", *verbose)
verbose has pointer type *bool. Call Parse only once, after all flags are defined and before flags are read. Flags must be passed before the non-flag arguments.
for i in paramcount do
begin
if paramstr(i)='-v' then
begin
verbose := true;
break;
end;
writeln('verbose is ',verbose);
end.
#!/usr/bin/perl -suse strict;
use warnings;
use vars qw($v);
$v ||= 0;
print'verbose is ' . ($v ? 'true' : 'false') . "\n";
The 'use vars' is how you tell Perl that (because of the -s flag) you are getting $v from the command line's -v. If you don't do this (with strict mode on) you will get an error.
public static void main(String[] args) {
boolean b = false;
for (String s : args)
if (s.equals("-v")) {
b = true;
break;
}
out.printf("verbose is %s", b);
}