Sponsored Content
Top Forums Shell Programming and Scripting Using perl code find greatest number. Post 302345430 by DemonixX on Wednesday 19th of August 2009 08:31:25 AM
Old 08-19-2009
Thxz balaji_red83! It working.

I changed a bit to make the result nicer:

Code:
my @nums = (2.1,1,3,10.1,10.2, 5);
my @sort_nums = sort {$a <=> $b} @nums;
my $grNum = pop @sort_nums;
print "Greatest Number is: $grNum\n"

~D~
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl find page number in a file

Hi i want to ask how can i use perl and find a word in a text file, and also telling that which page doesn't it exist? Eample: have a 10 pages text file, then i need to find 'Hello' in the file, and show that which page is it contain in. Output: Hello contains 8 times in page 1, 3, 4, 7, 10... (9 Replies)
Discussion started by: mingming88
9 Replies

2. Shell Programming and Scripting

finding greatest value in a column using awk from iostat output in linux

Friends, Need some help. On linux i have to run iostat command and in each iteration have to print the greatest value in each column. e.g iostat -dt -kx 2 2 | awk ' !/sd/ &&!/%util/ && !/Time/ && !/Linux/ {print $12}' 4.38 0.00 0.00 0.00 WHhat i would like to... (15 Replies)
Discussion started by: achak01
15 Replies

3. UNIX for Dummies Questions & Answers

help! script to select line with greatest value 2 between columns

Hi, I’m trying to do something I haven’t done before and I’m struggling with how to even create the command or script. I have the following space delim file: gene accession chr chr_st begin end NN1 NC_024540 chr3 - 14000 14020 NN1 ... (10 Replies)
Discussion started by: wolf_blue
10 Replies

4. Shell Programming and Scripting

Perl : print the sequence number without missing number

Dear Perl users, I need your help to solve my problem below. I want to print the sequence number without missing number within the range. E.g. my sequence number : 1 2 3 4 5 6 7 8 11 12 13 14 my desired output: 1 -8 , 11-14 my code below but still problem with the result: 1 - 14 1 -... (2 Replies)
Discussion started by: mandai
2 Replies

5. Shell Programming and Scripting

Perl - how to find the number based on the same name

Hi Perl Experts, Could somebody help me how to solve my problem if I have array contains the following data: "SEQ-0 UNSORT2 0", "SEQ-1 UNSORT2 1", "SEQ-2 UNSORT2 2", "SEQ-3 UNSORT2 3", <--- Missing the... (0 Replies)
Discussion started by: askari
0 Replies

6. Shell Programming and Scripting

Perl: find next available lowest number that is available in two arrays

Hi there. I have a number allocation problem whereby I have 2 arrays built from 2 different sources. The arrays will just contain a listed of sorted numbers @a 1 7 10 14 15 16 @b 1 7 10 11 14 15 16 (2 Replies)
Discussion started by: hcclnoodles
2 Replies

7. Shell Programming and Scripting

Take greatest value from second column

Dear All, Please help me, I have file input like this, 1 2142 215 2162 217 2842 285 2862 287 4002 401 4022 403 4822 1 2142 215 2162 217 2842 285 2862 287 4002 401 4022 403 4882 1 4801 (8 Replies)
Discussion started by: attila
8 Replies

8. Shell Programming and Scripting

Find and replace, perl code

Hi, Can somebody tell whats wrong with "find and replace perl code". I wanted to find "\n".write(status,data" and replace with "\n",data" in multipls files. #!/usr/bin/perl my @files = <*.c>; foreach $fileName (@files) { print "$fileName\n"; my $searchStr0 =... (4 Replies)
Discussion started by: chettyravi
4 Replies

9. Shell Programming and Scripting

awk to find number in a field then print the line and the number

Hi I want to use awk to match where field 3 contains a number within string - then print the line and just the number as a new field. The source file is pipe delimited and looks something like 1|net|ABC Letr1|1530||| 1|net|EXP_1040 ABC|1121||| 1|net|EXP_TG1224|1122||| 1|net|R_North|1123|||... (5 Replies)
Discussion started by: Mudshark
5 Replies
MouseX::Getopt(3pm)					User Contributed Perl Documentation				       MouseX::Getopt(3pm)

NAME
MouseX::Getopt - A Mouse role for processing command line options SYNOPSIS
## In your class package My::App; use Mouse; with 'MouseX::Getopt'; has 'out' => (is => 'rw', isa => 'Str', required => 1); has 'in' => (is => 'rw', isa => 'Str', required => 1); # ... rest of the class here ## in your script #!/usr/bin/perl use My::App; my $app = My::App->new_with_options(); # ... rest of the script here ## on the command line % perl my_app_script.pl -in file.input -out file.dump DESCRIPTION
This is a role which provides an alternate constructor for creating objects using parameters passed in from the command line. This module attempts to DWIM as much as possible with the command line params by introspecting your class's attributes. It will use the name of your attribute as the command line option, and if there is a type constraint defined, it will configure Getopt::Long to handle the option accordingly. You can use the trait MouseX::Getopt::Meta::Attribute::Trait or the attribute metaclass MouseX::Getopt::Meta::Attribute to get non-default commandline option names and aliases. You can use the trait MouseX::Getopt::Meta::Attribute::Trait::NoGetopt or the attribute metaclass MouseX::Getopt::Meta::Attribute::NoGetopt to have "MouseX::Getopt" ignore your attribute in the commandline options. By default, attributes which start with an underscore are not given commandline argument support, unless the attribute's metaclass is set to MouseX::Getopt::Meta::Attribute. If you don't want your accessors to have the leading underscore in their name, you can do this: # for read/write attributes has '_foo' => (accessor => 'foo', ...); # or for read-only attributes has '_bar' => (reader => 'bar', ...); This will mean that Getopt will not handle a --foo param, but your code can still call the "foo" method. If your class also uses a configfile-loading role based on MouseX::ConfigFromFile, such as MouseX::SimpleConfig, MouseX::Getopt's "new_with_options" will load the configfile specified by the "--configfile" option (or the default you've given for the configfile attribute) for you. Options specified in multiple places follow the following precedence order: commandline overrides configfile, which overrides explicit new_with_options parameters. Supported Type Constraints Bool A Bool type constraint is set up as a boolean option with Getopt::Long. So that this attribute description: has 'verbose' => (is => 'rw', isa => 'Bool'); would translate into "verbose!" as a Getopt::Long option descriptor, which would enable the following command line options: % my_script.pl --verbose % my_script.pl --noverbose Int, Float, Str These type constraints are set up as properly typed options with Getopt::Long, using the "=i", "=f" and "=s" modifiers as appropriate. ArrayRef An ArrayRef type constraint is set up as a multiple value option in Getopt::Long. So that this attribute description: has 'include' => ( is => 'rw', isa => 'ArrayRef', default => sub { [] } ); would translate into "includes=s@" as a Getopt::Long option descriptor, which would enable the following command line options: % my_script.pl --include /usr/lib --include /usr/local/lib HashRef A HashRef type constraint is set up as a hash value option in Getopt::Long. So that this attribute description: has 'define' => ( is => 'rw', isa => 'HashRef', default => sub { {} } ); would translate into "define=s%" as a Getopt::Long option descriptor, which would enable the following command line options: % my_script.pl --define os=linux --define vendor=debian Custom Type Constraints It is possible to create custom type constraint to option spec mappings if you need them. The process is fairly simple (but a little verbose maybe). First you create a custom subtype, like so: subtype 'ArrayOfInts' => as 'ArrayRef' => where { scalar (grep { looks_like_number($_) } @$_) }; Then you register the mapping, like so: MouseX::Getopt::OptionTypeMap->add_option_type_to_map( 'ArrayOfInts' => '=i@' ); Now any attribute declarations using this type constraint will get the custom option spec. So that, this: has 'nums' => ( is => 'ro', isa => 'ArrayOfInts', default => sub { [0] } ); Will translate to the following on the command line: % my_script.pl --nums 5 --nums 88 --nums 199 This example is fairly trivial, but more complex validations are easily possible with a little creativity. The trick is balancing the type constraint validations with the Getopt::Long validations. Better examples are certainly welcome :) Inferred Type Constraints If you define a custom subtype which is a subtype of one of the standard "Supported Type Constraints" above, and do not explicitly provide custom support as in "Custom Type Constraints" above, MouseX::Getopt will treat it like the parent type for Getopt purposes. For example, if you had the same custom "ArrayOfInts" subtype from the examples above, but did not add a new custom option type for it to the "OptionTypeMap", it would be treated just like a normal "ArrayRef" type for Getopt purposes (that is, "=s@"). METHODS
new_with_options (%params) This method will take a set of default %params and then collect params from the command line (possibly overriding those in %params) and then return a newly constructed object. The special parameter "argv", if specified should point to an array reference with an array to use instead of @ARGV. If "GetOptions" in Getopt::Long fails (due to invalid arguments), "new_with_options" will throw an exception. If Getopt::Long::Descriptive is installed and any of the following command line params are passed, the program will exit with usage information (and the option's state will be stored in the help_flag attribute). You can add descriptions for each option by including a documentation option for each attribute to document. --? --help --usage If you have Getopt::Long::Descriptive the "usage" param is also passed to "new" as the usage option. ARGV This accessor contains a reference to a copy of the @ARGV array as it originally existed at the time of "new_with_options". extra_argv This accessor contains an arrayref of leftover @ARGV elements that Getopt::Long did not parse. Note that the real @ARGV is left un- mangled. usage This accessor contains the Getopt::Long::Descriptive::Usage object (if Getopt::Long::Descriptive is used). help_flag This accessor contains the boolean state of the --help, --usage and --? options (true if any of these options were passed on the command line). meta This returns the role meta object. AUTHORS
o NAKAGAWA Masaki <masaki@cpan.org> o FUJI Goro <gfuji@cpan.org> o Stevan Little <stevan@iinteractive.com> o Brandon L. Black <blblack@gmail.com> o Yuval Kogman <nothingmuch@woobling.org> o Ryan D Johnson <ryan@innerfence.com> o Drew Taylor <drew@drewtaylor.com> o Tomas Doran <bobtfish@bobtfish.net> o Florian Ragwitz <rafl@debian.org> o Dagfinn Ilmari Mannsaker <ilmari@ilmari.org> o Avar Arnfjord Bjarmason <avar@cpan.org> o Chris Prather <perigrin@cpan.org> o Mark Gardner <mjgardner@cpan.org> COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by Infinity Interactive, Inc. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. perl v5.14.2 2012-03-21 MouseX::Getopt(3pm)
All times are GMT -4. The time now is 11:58 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy