help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: getopt


From: Juergen Rose
Subject: Re: getopt
Date: Sun, 11 Oct 2009 02:57:34 +0200

Am Samstag, den 10.10.2009, 10:14 -0400 schrieb Ben Abbott:
> On Oct 10, 2009, at 5:16 PM, Juergen Rose wrote:
> 
> > Am Samstag, den 10.10.2009, 10:48 +0000 schrieb address@hidden:
> >> did you see   varargin?
> >>
> >> Doug
> >>
> >>> Subject: getopt
> >>> From: address@hidden
> >>> To: address@hidden
> >>> Date: Sat, 10 Oct 2009 19:55:35 +0200
> >>>
> >>> Hi,
> >>>
> >>> I am looking for a possibility to evaluate the arguments passed to a
> >>> octave script similar to getopt[s] in bash or Getopt::Std in perl.
> >>>
> >>> Any hints are appreciated.
> >
> > Hi Doug,
> >
> > I don't understand, what 'varargin' has to do with 'getopt'.
> >
> > octave:1> help varargin
> >
> > -- Keyword: varargin
> >     Pass an arbitrary number of arguments into a function.
> >
> >     See also: varargout, nargin, nargout
> >
> > I need a function, which I can use to parse arg_list = argv() and  
> > which
> > can distinguish between allowed and not allowed options, and between
> > options with and without additional parameter.
> > I.e., I look for something like in Perl:
> >
> > use Getopt::Std;
> > my $opts="dhS:o:N:n:";
> > my $options={};
> > getopts($opts,$options);
> > if (defined $options->{d}) {$DBG_LVL=$options->{d};}
> > if (defined $options->{h}) {usage();   exit 0;}
> > if (defined $options->{S}) {$Seed=$options->{S};}
> > ..
> >
> > Regards Juergen
> 
> Within a function ...
> 
>       nargin = the number of arguments passed.
>       varargin{n} = the nth argument
> 
> The variables nargout and vargout are the output counterparts.
> 
> Below is a very simple example illustrating how varargin works.
> 
> octave:1> function test_varargin (varargin)
>  > varargin{:}
>  > end
> octave:2> test_varargin (1, 2, 3, "a", "b", "c")
> ans =  1
> ans =  2
> ans =  3
> ans = a
> ans = b
> ans = c
> octave:3>
> 
> Ben

Hi Ben,
I not yet understand what varagin has to do with the function getopts,
besides the fact that you can perhaps use varagin to write my own
function getopts. But I hoped this is already done.

If I try to write a function my_getopt, the testing of the options is
probably not so hard. But how I can reset argv, that it after the call
the call of my_getopt contains only the non option arguments, I have no
idea.
Juergen




reply via email to

[Prev in Thread] Current Thread [Next in Thread]