Professional Web Applications Themes

Accessing elements in array ref of array references - PERL Miscellaneous

Currently I'm comparing the first value of each of the array references (which are stored in an array reference $ref_ref) as follows: if(map($_->[0] =~ /$keyword/i,$ref_ref)) { # Do something cunningly clever... } What I was wondering about (for no particular reason) is doing something like: if(map(/$keyword/i,cool_function($ref_ref, 0))) { # Do something equally cunningly clever... } Any idea's? (or should I get back to work ;)...

  1. #1

    Default Accessing elements in array ref of array references

    Currently I'm comparing the first value of each of the array
    references (which are stored in an array reference $ref_ref) as
    follows:

    if(map($_->[0] =~ /$keyword/i,$ref_ref))
    {
    # Do something cunningly clever...
    }

    What I was wondering about (for no particular reason) is doing
    something like:

    if(map(/$keyword/i,cool_function($ref_ref, 0)))
    {
    # Do something equally cunningly clever...
    }

    Any idea's? (or should I get back to work ;)
    fatted Guest

  2. #2

    Default Re: Accessing elements in array ref of array references

    fatted wrote:
    > Currently I'm comparing the first value of each of the array
    > references (which are stored in an array reference $ref_ref) as
    > follows:
    > if(map($_->[0] =~ /$keyword/i,$ref_ref))
    > {
    > # Do something cunningly clever...
    > }
    okay...
    > What I was wondering about (for no particular reason) is doing
    > something like:
    > if(map(/$keyword/i,cool_function($ref_ref, 0)))
    > {
    > # Do something equally cunningly clever...
    > }
    well, i can't see any reason either, but this would do it:
    sub cool_function(\$) {
    map $_->[ $_[1] ] => { $_[0] }
    }

    hth, tina
    --
    [url]http://www.tinita.de/[/url] \ enter__| |__the___ _ _ ___
    [url]http://Movies.tinita.de/[/url] \ / _` / _ \/ _ \ '_(_-< of
    [url]http://www.perlquotes.de/[/url] \ \ _,_\ __/\ __/_| /__/ perception
    - my mail address expires end of august 2003 -
    Tina Mueller Guest

  3. #3

    Default Re: Accessing elements in array ref of array references

    Tina Mueller wrote:
    > well, i can't see any reason either, but this would do it:
    > sub cool_function(\$) {
    > map $_->[ $_[1] ] => { $_[0] }
    > }
    or without prototype:
    sub cool_function {
    my $n = pop;
    map $_->[$n] => _
    }
    or:
    sub cool_function {
    map $_->[ $_[-1] ] => _[0..$#_-1]
    }

    now *I* should get back to work =)
    --
    [url]http://www.tinita.de/[/url] \ enter__| |__the___ _ _ ___
    [url]http://Movies.tinita.de/[/url] \ / _` / _ \/ _ \ '_(_-< of
    [url]http://www.perlquotes.de/[/url] \ \ _,_\ __/\ __/_| /__/ perception
    - my mail address expires end of august 2003 -
    Tina Mueller Guest

  4. #4

    Default Re: Accessing elements in array ref of array references


    "Greg Bacon" <gbaconhiwaay.net> wrote in message
    news:vgtg7jqdhbkk67corp.supernews.com...
    > In article <4eb7646d.0307110111.4a18dd1dposting.google.com >,
    > fatted <fatted> wrote:
    >
    > : [...]
    > :
    > : What I was wondering about (for no particular reason) is doing
    > : something like:
    > :
    > : if(map(/$keyword/i,cool_function($ref_ref, 0)))
    > : {
    > : # Do something equally cunningly clever...
    > : }
    > :
    > : Any idea's? (or should I get back to work ;)
    >
    > If I understand you, cool_function would be equivalent to
    >
    > sub cool_function {
    > my $i = pop;
    > map $_->[$i], _;
    > }
    >
    > We're discussing things at such a low level that we may be obscuring
    > an XY problem. What are you trying to do?
    What I was interested in was keeping the map structure as I would normally
    use it for mapping over a "normal" array and matching against $_ (eg
    map(/$keyword/i,...), but mapping over the 0th element in each of the array
    references which are stored in the array reference. Basically form an array,
    which contains all the 0th elements of the array references, and then map
    over it. If that makes sense :) I've no particular need to for this, but
    just curiosity to see if I could form the map statement slightly
    differently. (I think I'm forming an unhealthy fascination with map :)


    Fatted Guest

Similar Threads

  1. #40385 [NEW]: inserting references to an array
    By viqq at gazeta dot pl in forum PHP Bugs
    Replies: 1
    Last Post: February 7th, 12:45 PM
  2. object references stored in array gives me what?
    By lawrence in forum PHP Development
    Replies: 4
    Last Post: October 18th, 03:33 PM
  3. Bug or featuusing array references
    By Uli Tuerk in forum PERL Miscellaneous
    Replies: 6
    Last Post: August 5th, 11:50 PM
  4. sort array of hash references
    By llama in forum PERL Miscellaneous
    Replies: 1
    Last Post: July 29th, 07:53 AM
  5. Confused with array and references
    By Bernard El-Hagin in forum PERL Miscellaneous
    Replies: 7
    Last Post: July 5th, 06:41 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139