Re: accessing arrays in a different sub-routine
From: A. Sinan Unur (1usa_at_llenroc.ude.invalid)
Date: 03/29/05
- Next message: Ala Qumsieh: "Re: Class instances with 'use overload' in a tied hash"
- Previous message: PerlFAQ Server: "FAQ 5.26 How do I print to more than one file at once?"
- In reply to: erik: "Re: accessing arrays in a different sub-routine"
- Next in thread: Ala Qumsieh: "Re: accessing arrays in a different sub-routine"
- Reply: Ala Qumsieh: "Re: accessing arrays in a different sub-routine"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 28 Mar 2005 23:05:53 GMT
"erik" <ewitkop90@hotmail.com> wrote in news:1112049496.433969.94040
@g14g2000cwa.googlegroups.com:
> I just read that, thanks.
Please quote an appropriate amount of context when replying.
> That sheds some light. So basically with my
> example above, and due to it's dynamic nature, the only way I can get
> this working is a sub-function within a subfunction. I really didn't
> want to do that, but I take it I have no choice.
You lost me here.
Here is a simple example of what you can do:
#! /usr/bin/perl
my $files = read_files_in_current_dir();
$files or die "No files in current directory\n";
my_print($files);
sub read_files_in_current_dir {
opendir my $dir, '.'
or die "Cannot open current directory: $!";
[ grep { -f } readdir $dir ];
}
sub my_print {
print "$_\n" for sort @{ shift() };
}
__END__
The first subroutine you call generates the array you want, and returns
a reference to it. Then, you pass that reference to other subroutines
that work on the array.
No need for nested subroutines.
> BTW, what was wrong with the name that I gave my array
> @bandwidth_array? You lost me on that one.
For me, the '@' in front of the name already signifies that the variable
is an array, why replicate that information?
Sinan
- Next message: Ala Qumsieh: "Re: Class instances with 'use overload' in a tied hash"
- Previous message: PerlFAQ Server: "FAQ 5.26 How do I print to more than one file at once?"
- In reply to: erik: "Re: accessing arrays in a different sub-routine"
- Next in thread: Ala Qumsieh: "Re: accessing arrays in a different sub-routine"
- Reply: Ala Qumsieh: "Re: accessing arrays in a different sub-routine"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|