Re: wildcard arrays or lists



On May 9, 10:14 am, anansi <kaz...@xxxxxxxxx> wrote:
I wondered if it is possible to tell ruby to accept wildcards in arrays
or lists. I have a function which relys on .each and accepts arrays and
lists of IP's. Is it possible to use wildcards in an array like

buff = Array(127.0.*.*)

of couse this is not working but is there any way to do this? Or is my
only option to fill the array "by hand" with a loop with every single IP?

The problem is what do you mean by "*"? Is it limited to numbers or
can letters be included? Since you're specifying an IP address in
this case, you are probably limiting it to a finite set of positive
integers. You could use a number of Ruby iterators to fill in all
possible combinations (Array#upto immediately comes to mind; ie:
0.upto(127) {|i| buff.push "127.0.#{i}.0"} - of course you'll need to
have two loops to fill in the two last numbers).

But I'm curious as to why you want to do this in the first place. I'm
thinking that a regular expression might be more suitable; however, I
can't be sure without more information.

.



Relevant Pages

  • Re: Reference other array objects from within loop?
    ... simulate trading programs in CL. ... each and every object in the array. ... facing right now is because of the nature of the code within the loop. ... Be careful with circular lists; don't pass them to LENGTH, and make sure to set *print-circle* to t. ...
    (comp.lang.lisp)
  • Re: garbage collection problem in large linked lists
    ... Instead all buckets are allocated at once in an array. ... VG.net, which must be very scalable, but only for lists which would normally ... Linked lists require pointer dereferencing in order to traverse. ... When you run out of space, you allocate a new smaller array. ...
    (microsoft.public.dotnet.framework.performance)
  • Re: Dict sharing vs. duplication
    ... array to enforce unique keys and I use lists to enforce order. ... API in a page or two of Tcl code, it isn't so much a missing feature ... OpenACS database API which creates a new specialized data structure, ...
    (comp.lang.tcl)
  • Re: Translating python to scheme
    ... Scheme has mutation, and there are reasons to use it. ... confusing when considering a 2d array. ... in other languages: Lisp Lists and Vectors. ...
    (comp.lang.scheme)
  • Re: [opensuse] bash - why doesnt the tldp bash beginners guide for loop example work?
    ... I have run into a bash problem with a simple for loop I don't ... The echo statement showed that $i was receiving the ... I personally like to use array variables in BASH scripting. ... lists to operate on. ...
    (SuSE)