Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

References and subroutine ?
Hello,

I have an array and I would like to pass it to a subroutine:

&printlist(\@array);


sub printlist
{
my $array_ref = (shift);
my $max;
my $maxnew = @{$array_ref};
for(my $i=0;$i < $maxnew; $i++){
print "\t\t\t\t\t";

if ( ($maxnew - $i) >= 10 ) {
$max = 10;
} else {
$max = $maxnew - $i;
}

for(my $n=0; $n <= $max; $n++) {
print "${$array_ref}[$i]\t";
$n++;
$i++;
}
print "\n";
}

}


I know the above works I just want to make sure I understand why,

I am passing the reference of an to the subroutine, which using (shift)
assigns the first scaler to my scaler array_ref. So now array_ref scaler
is equal to the passed scaler allowing me to use array_ref as a
reference.

Correct ?

Michael



Report this thread to moderator Post Follow-up to this message
Old Post
Michael Gale
04-22-05 08:57 PM


RE: References and subroutine ?
Michael Gale <mailto:michael.gale@pason.com> wrote:

: I am passing the reference of an to the subroutine, which using
: (shift) assigns the first scaler to my scaler array_ref. So now
: array_ref scaler is equal to the passed scaler allowing me to use
: array_ref as a reference.
:
: Correct ?

Yes, except you're misspelling 'scalar'. Perl places a
reference to @array into @_ when you call the subroutine. When you
use 'shift', you remove the first item from @_ (which is an array
reference) and set it to $array_ref.


HTH,

Charles K. Clarkson
--
Mobile Homes Specialist
254 968-8328


Report this thread to moderator Post Follow-up to this message
Old Post
Charles K. Clarkson
04-22-05 08:57 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:23 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.