Title: RE: passing parms to subroutine

Look for dereferencing. Section 4.8.2 in Perl in a Nutshell


-----Original Message-----
From: lorid [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, October 29, 2003 2:14 PM
To: Moon, John
Cc: perl users
Subject: Re: passing parms to subroutine


Thanks.
I didnt see anything about the $$ for refering to the value in my book , but then again Im in a hurry. anyway - I get it, it works now

Lori

"Moon, John" wrote:

> SUN1-BATCH>perl -e 'my $a="abc"; &Show(\$a);sub Show {my
> SUN1-BATCH>($value)[EMAIL PROTECTED];print
> "value=$$value\n";}'
> value=abc
> SUN1-BATCH>
>
> Hope this helps ...
>
> jwm
>
> -----Original Message-----
> From: lorid [mailto:[EMAIL PROTECTED]]
> Sent: October 29, 2003 14:31
> To: perl users
> Subject: passing parms to subroutine
>
> Im used to subs in C or VB but this has me puzzled...
> I am trying to pass a scalar ref to a subroutine,
> When I try to use the value of the passed parm inside the sub Im
> getting a garbage value (has address instead of  value? ) from my
> process_files sub,and the increment sub, but the sub that I dont
> declare a prototype on or use () in the func. definition It works ??
>
> Can someone spot my error, or tell me the right way to pass a scalar
> to a sub and use it ?
>
> #!/usr/bin/perl -w
> use warnings;
> use strict;
>
> #prototypes
> sub increment(\$);
> sub process_files(\$);
>
> my $a= 5;
> my $pc_unzipped_file =
> 'C:\\TMCC\\CIT_153\\hw9\\hw9_files\\CNUTLZD.TXT';
>
> increment($a);
> print $a;
> process_files($pc_unzipped_file);
>
> my $a= 5;
> my $pc_unzipped_file =
> 'C:\\TMCC\\CIT_153\\hw9\\hw9_files\\CNUTLZD.TXT';
>
> increment($a);
> print $a;
>
> process_files($pc_unzipped_file);
>
> #function defs
> sub increment(\$){
>
>   my $reference = shift;
>
>   print "\nThe reference:$reference\n";
>   print "\nThe reference:@_\n";
>
>   $$reference++;
>
> }
>
> sub process_files(\$){
>
>   my $file_ref = shift;
>
>   print "\nGot the Filename: $file_ref \n";
>
>    print "\nGot the Filename: @_\n";
> }
>
> first (1,2,3);
> sub  first                                               #how come no ()
> here ? , also I notice they dont create a prototype
> {
>   print "\nIn first the ars are @_\n";          # this allows me to get
> at values inside the sub which is what I need.
> }
>
> Thanks
>
> Lori
>
> _______________________________________________
> Perl-Win32-Users mailing list
> [EMAIL PROTECTED]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

_______________________________________________
Perl-Win32-Users mailing list [EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to