I'm starting to get this...

A couple more questions:

1.  What is a sigil?

2.  I like to make little reference pages for myself, do these terms look
right?

# pointers are scalars

# GETTING POINTERS

\$mystring;       # returns a pointer to mystring
\@myarray;        # returns a pointer to myarray
\%myhash;         # returns a pointer to myhash

# FOLLOWING POINTERS

${ $pointer };    # returns string pointed to by $pointer
                  # $pointer can be replaced with anything
                  #   that returns a pointer as a scalar

@{ $pointer }[0]; # returns first element (element zero)
                  # of the array pointed to by $pointer
$pointer->[0];    # (same)

%{ $pointer }{$somekey};  # returns hash value of hash pointed
                          # to by $pointer, key $somekey

# CREATING STRUCTURES

[ @myarray $mystring ];  # returns a pointer to a new copy of
                         # a new array containing @myarray with
                         # $mystring at the end


(For those who are beginners like me, don't assume these are right until a
smart person says so.  =)

TIA.

- Bryan

__________________


On Jun 6, Nikola Janceski said:

>$$onediminsional_hash_ref{$key}
>@$onediminsional_array_ref[$index]

The leading sigil denotes the amount of stuff being returned, NOT the data
structure being worked with!  It is the {} and [] that determine the data
structure.

  @ARRAY = (1 .. 10);
  $x = \@ARRAY;
  %HASH = (a => 'b', c => 'd');
  $y = \%HASH;

  print $x->[1];  # 2
  print $$x[1];   # also 2
  print @$x[1];   # ALSO 2 (the list (2))

  print $x->[1,4];  # 5
  print $$x[1,4];   # still 5
  print @$x[1,4];   # 25 (the list (2,5))

Why is $$x[1,4] '5' instead of ('2','5')?  Because the leading $ demands
scalar context inside the subscript, so scalar(1,4) => 4, and $$x[4] is 5.

Likewise with hashes.

  print $y->{a};  # 'b'
  print $$y{a};   # 'b'
  print @$y{a};   # 'b'

  print $y->{'a','c'};  # 'd'
  print $$y{'a','c'};   # 'd'
  print @$y{'a','c'};   # 'bd'

Notice, if you will, that while

  print @ARRAY[1];

yields a "@ARRAY[1] better written as $ARRAY[1]" warning,

  print @$x_ref[1];

does not.

--
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to