Richard Lee wrote:
John W. Krahn wrote:
Richard Lee wrote:
Chas. Owens wrote:

They do similar, but different, things. The \ operator takes a reference to a variable and [] operator creates an anonymous array. You can build [] from \ by using a temporary array that goes out of scope.

my $linked = [EMAIL PROTECTED];
my $independent = do { #this is functionally the same as my $independent = [EMAIL PROTECTED];
    my @temp = @array;
    [EMAIL PROTECTED];
}

Changes to @$linked will change @array, but changes to @$independent will not.

one more question,

why does below not work?


while ( my ($key,$value) = each( %{$oj_s} ) ) {
      print "$key and $value\n";
}

assuming that

oj_s contains

$VAR1 = {
         'abc' => '10.0.0.1_1035',
         'cde' => '192.168.1.1_1037',
         'fgh' => '192.168.100.1_10',
         }

It works for me:

$ perl -le'
my $oj_s = {
    abc => "10.0.0.1_1035",
    cde => "192.168.1.1_1037",
    fgh => "192.168.100.1_10",
    };
while ( my ($key,$value) = each( %{$oj_s} ) ) {
    print "$key and $value";
    }
'
fgh and 192.168.100.1_10
cde and 192.168.1.1_1037
abc and 10.0.0.1_1035



John

For some strange reason, my problem was that

process_it('something', \%hash_table);

sub process_it {
    my($variable, $hash_table) = shift;

}

when I change to separate shift

my $variable = shift;
my $hash_table = shift;

it worked...   are they different?

perldoc -f shift
    shift ARRAY
    shift   Shifts the first value of the array off and returns it,
            shortening the array by 1 and moving everything down.


If you want to remove two or more elements from an array you could use splice(), or the usual way to do what you want is:

sub process_it {
    my($variable, $hash_table) = @_;



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to