1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Perl References

Discussion in 'CIW Certifications' started by palgrave, Dec 3, 2006.

  1. palgrave

    palgrave New Member

    5
    0
    1
    Can anybody explain perl references in plain english? I was quite enjoying learning perl up to this point, but none of the (scheidegger/skillstrain) course material is sinking in on this one.

    Right from the top if you don't mind!
     
  2. hbroomhall

    hbroomhall Petabyte Poster Gold Member

    6,623
    115
    224
    Can you tell us what other prog languages you know (such as C or C++). The answer I give will depend on that.

    (i.e. perl references are very similar to some constructs in certain other languages)

    BTW - welcome to CF!

    Harry.
     
    Certifications: ECDL A+ Network+ i-Net+
    WIP: Server+
  3. palgrave

    palgrave New Member

    5
    0
    1
    PHP HTML and CSS
     
  4. palgrave

    palgrave New Member

    5
    0
    1
    P.S. Sorry I didn't reply earlier. Been away with work doing a job I hate, but it motivates me to do CIW!
     
  5. ffreeloader

    ffreeloader Terabyte Poster

    3,661
    106
    167
    Certifications: MCSE, MCDBA, CCNA, A+
    WIP: LPIC 1
  6. hbroomhall

    hbroomhall Petabyte Poster Gold Member

    6,623
    115
    224
    Well - if you know PHP, what problem are you having with Perl references? The essential property of a reference is virtualy the same in both languages!

    Harry.
     
    Certifications: ECDL A+ Network+ i-Net+
    WIP: Server+
  7. ffreeloader

    ffreeloader Terabyte Poster

    3,661
    106
    167
    LOL. He's probably having the same problem as lot of Perl newbies: trying to read what can become an absolutely confusing syntax when it's written really tersely. At least that's what happens with me. After two or three chapters in every book on Perl I've seen the syntax looks like $*&#^@%^@)-+_)(* to the newb because the authors will jump from using a fairly easily understandable syntax into really terse syntax without warning or real explanantion. It's not easy for the Perl newb to follow, at least it wasn't for me.
     
    Certifications: MCSE, MCDBA, CCNA, A+
    WIP: LPIC 1
  8. hbroomhall

    hbroomhall Petabyte Poster Gold Member

    6,623
    115
    224
    <Grin> - yes - Perl does have a tendancy to look like line noise at times! And heavy use of Regexp doesn't help either!

    But I think the OP needs to be a little more specific on the problems he is having. It is, of course, entirely possible that he never encountered references in PHP - it is sometimes possible to construct applets without using them at all.

    Harry.
     
    Certifications: ECDL A+ Network+ i-Net+
    WIP: Server+
  9. palgrave

    palgrave New Member

    5
    0
    1
    Hope you enjoyed your wee chat there. It doesn't matter. I will get help from helpful people elsewhere.
     
  10. ffreeloader

    ffreeloader Terabyte Poster

    3,661
    106
    167
    Ummm.... Just what the heck is that supposed to mean?

    I gave a you a link chock full of Perl resources.
     
    Certifications: MCSE, MCDBA, CCNA, A+
    WIP: LPIC 1
  11. tripwire45
    Honorary Member

    tripwire45 Zettabyte Poster

    13,493
    179
    287
    I'm coming in late on this conversation. Not sure what sparked this response from you, palgrave. Reading the "crosstalk" between Harry and Freddy is pretty informative.

    Perl is one of the most well documented (IMHO) programming languages around. There are *tons* of online references. The group I work with use Perl as one of their development languages. When I was hired to consolidate and update their Intranet and Knowledge Base, I started with Perl because it was so easy to find information from a variety of sources (and Perl programmers seem like such a hoot). :biggrin
     
    Certifications: A+ and Network+
  12. stuPeas

    stuPeas Megabyte Poster

    774
    12
    76
    I understand your problem, I had it myself. If you keep your eye on this thread I will get back to you with a good explanation.

    Stu
     
    Certifications: C&G Electronic, CIW Associate (v5).
    WIP: CIW (Website Design Manager)
  13. stuPeas

    stuPeas Megabyte Poster

    774
    12
    76
    Whenever you create a variable, say $a, then that variables VALUE (This is important, Its the value inside the variable),is stored in your computers memory at a location specified by a number (Hex i think). You are not aware of this number yourself, all you know that is if you want access to the variable then you get to it through the Pointer that you gave it ($a). This is all to do with symbol tables, which you will come up against later.

    Now whenever you prefix the variable name with the \ operator,
    ie \$a you are specifying the address that the VALUE in $a is stored in (as above). For example, if $a="fish" and "fish is stored in the memory location A67F, then when you specify $a in your program it accesses this location and returns "fish".

    When you say \$a, you will not access "fish" because the value in \$a is the memory location number only, AND NOT THE VALUE INSIDE IT.

    \$a on its own is often not much use so you usually see $b=\$a.
    Now $b stores the memory address that the VALUE inside $a is stored at. If you print $b it will print out the address of the variable stored in $a.

    Now the computer Knows that $b stores a reference, so if you want to access the actual value stored in $a (ie. the value inside the memory address pointed to by the reference $b),
    then you have to type $$b.

    RECAP.

    $a="fish" "fish stored at location 1234 in memory)
    \$a = 1234 (The memory location that $a points to)
    $b =\$a (now $b also holds 1234)
    print ("$b"); will give 1234.

    print ("$$b"); will give "fish".


    When you look at the reasons for the use of references, the It makes more sense

    follow this "Bless My Referents"

    http://www.perl.com/1pt/a/469
     
    Certifications: C&G Electronic, CIW Associate (v5).
    WIP: CIW (Website Design Manager)
  14. palgrave

    palgrave New Member

    5
    0
    1
    Thanks very much stupeas. That is a very clear explanation. A trawl through resources very rarely brings up plain English. Well done!
     
  15. Belmont

    Belmont Bit Poster

    22
    0
    21
    Thank you!
     
    Certifications: none related
    WIP: Master CIW Web Site Manager

Share This Page

Loading...