Ask a Question related to PERL Miscellaneous, Design and Development.

  1. #1

    Default Re: Variable reference

    Par <paer_nystroem@hotmail.com> wrote:
    > I have a lot of variables in the form of
    > $var{$something} = "Some text";
    >
    > $something consists of two parts though. Ideally I would have liked it
    > to be in the form of $var{$part1$part2}, but that doesn't work...
    > So the really nasty looking part I've had to add is
    > $something = $part1 . $part2;
    >
    > So my question is basically how I avoid having the above line?!

    $var{ $part1 . $part2 }
    or
    $var{ "$part1$part2" }


    --
    Tad McClellan SGML consulting
    [email]tadmc@augustmail.com[/email] Perl programming
    Fort Worth, Texas
    Tad McClellan Guest

  2. Similar Questions and Discussions

    1. Reference Items in a Session Variable
      I am attempting to reference specific items in a session variable. I can access the "Session.Basket.CurrentRow" of any particular ROW , e.g. (...
    2. Reference a variable in a repeater
      I have some code that worked fine until a created a repeater. I get an error (BC30451) that I've researched on Google groups, etc., to no avail. ...
    3. Help with variable reference in perl OOD
      I need to be able to set a variable equal to the value of an OOD reference such that when the reference changes, the the variable changes as well...
    4. passing global variable by reference?
      I'm trying to stick my frequently used subroutines into a Sysadmin.pm module. Of course the first one I tried uses global variables and I wondering...
    5. Reference a VBScript Variable in ASP
      This is my VBScript function: <script language="JavaScript" type="text/JavaScript"> Dim UN Set objNet = CreateObject("WScript.NetWork") Set...
  3. #2

    Default Re: Variable reference

    On 21 Jul 2003, Par wrote:
    >$var{$something} = "Some text";
    >
    >$something consists of two parts though. Ideally I would have liked it
    >to be in the form of $var{$part1$part2}, but that doesn't work...
    >So the really nasty looking part I've had to add is
    >$something = $part1 . $part2;
    >
    >So my question is basically how I avoid having the above line?!
    Just do

    $var{$part1 . $part2}

    or

    $var{"$part1$part2"}

    --
    Jeff Pinyan RPI Acacia Brother #734 2003 Rush Chairman
    "And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
    years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
    Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)

    Jeff 'japhy' Pinyan Guest

  4. #3

    Default Re: Variable reference

    Hi,

    You should use $var{ $a, $b } = "Some text";
    The key would be $a . $; . $b
    $; is set to \034 but you can change it to any character you like.

    This is an example to print the keys and values.
    for my $key ( keys %var ){
    my ( $a, $b ) split /$;/, $key;
    print "key $a, $b has value $var{ $key }\n"
    }

    Jeff 'japhy' Pinyan wrote:
    > On 21 Jul 2003, Par wrote:
    >
    >
    >>$var{$something} = "Some text";
    >>
    >>$something consists of two parts though. Ideally I would have liked it
    >>to be in the form of $var{$part1$part2}, but that doesn't work...
    >>So the really nasty looking part I've had to add is
    >>$something = $part1 . $part2;
    >>
    >>So my question is basically how I avoid having the above line?!
    >
    >
    > Just do
    >
    > $var{$part1 . $part2}
    >
    > or
    >
    > $var{"$part1$part2"}
    >
    Shawn Corey Guest

  5. #4

    Default Re: Variable reference

    [ Please don't top-post;
    your reply should come after the original text ]

    Also sprach Shawn Corey:
    > You should use $var{ $a, $b } = "Some text";
    > The key would be $a . $; . $b
    > $; is set to \034 but you can change it to any character you like.
    >
    > This is an example to print the keys and values.
    > for my $key ( keys %var ){
    > my ( $a, $b ) split /$;/, $key;
    > print "key $a, $b has value $var{ $key }\n"
    > }
    While the above is certainly right from a technical standpoint, I
    stumbled over your first sentence:
    > You should use $var{ $a, $b } = "Some text";
    I think this misses the point of the OP. He was essentially just asking
    how to concatenate two strings to one hash-key. Using $hash{ LIST }
    however is a Perl4ism. In a time when references weren't yet there, Perl
    needed a way to work with multidimensional data-structures. Joining the
    elements of the list together with $; was therefore just a work-around.
    Nowadays fortunately perl knows about references and thus the
    multidimensional array emulation is no longer needed.

    Tassilo
    --
    $_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
    pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus}) !JAPH!qq(rehtona{tsuJbus#;
    $_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexi ixesixeseg;y~\n~~dddd;eval
    Tassilo v. Parseval Guest

  6. #5

    Default Re: Variable reference

    On 21 Jul 2003, Tassilo v. Parseval wrote:
    >> You should use $var{ $a, $b } = "Some text";
    >> The key would be $a . $; . $b
    >> $; is set to \034 but you can change it to any character you like.
    >
    >I think this misses the point of the OP. He was essentially just asking
    >how to concatenate two strings to one hash-key. Using $hash{ LIST }
    >however is a Perl4ism. In a time when references weren't yet there, Perl
    >needed a way to work with multidimensional data-structures. Joining the
    >elements of the list together with $; was therefore just a work-around.
    >Nowadays fortunately perl knows about references and thus the
    >multidimensional array emulation is no longer needed.
    Although, as was stated, you could set $; to "", and thereby make it work
    like the OP wanted. ;)

    --
    Jeff Pinyan RPI Acacia Brother #734 2003 Rush Chairman
    "And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
    years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
    Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)

    Jeff 'japhy' Pinyan Guest

Posting Permissions

  • You may not post new threads
  • You may 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