[oclug] Perl question

Brian Johnson bjohnson at jecinc.on.ca
Tue Mar 26 13:48:29 EST 2002


My code is 17kb and includes multiple specialized Perl modules including
ones that communicate with Palm PDA .pdb files - I tried to simplify what I
was doing to conserve bandwidth and highlight what the actural problem was.

But ... since I still can't get it to work and you asked ...

I've attached the perl program (I hope the mailing list doesn't mind too
much)


-----Original Message-----
From: oclug-admin at lists.oclug.on.ca
[mailto:oclug-admin at lists.oclug.on.ca]On Behalf Of Dave O'Neill
Sent: Monday, March 25, 2002 4:59 PM
To: oclug at lists.oclug.on.ca
Subject: Re: [oclug] Perl question


On Mon, Mar 25, 2002 at 01:55:23PM -0500, Brian Johnson wrote:
> I am using push to add items to an array
[ snip ]
> It loops through the correct number of times, but $item2 always equals the
> value of the last $item that was pushed into @items

It's generally more helpful to post your actual code when asking for help,
as contrived examples aren't always helpful in solving the problem.

Anyway, I tried the following, based on what you wrote above, and it works:

#!/usr/bin/perl -w
use strict;
my $item;
my @items;
foreach $item (qw(one two three four)) {
    push @items, $item
}

my $item2;
my @items2 = @items;
foreach $item2 (@{items2}) {
    print $item2,"\n";
}
__END__

And here's what it gives me when run:

dmo at talisker 16:52:37 {204} perl foo.pl
one
two
three
four

> Clear as mud?  How do I get the array pointer to point back at the
beginning
> of the array for the for loop?

What array pointer?

-dave0
--
    ('>
    //\  dmo at acm dot org
    v_/_
_______________________________________________
oclug mailing list
oclug at lists.oclug.on.ca
http://www.oclug.on.ca/mailman/listinfo/oclug
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fetch-mail
Type: application/octet-stream
Size: 15144 bytes
Desc: not available
Url : http://tux.oclug.on.ca/pipermail/oclug/attachments/20020326/682a5cb4/fetch-mail.obj


More information about the OCLUG mailing list