Re: Have sub routine handle file OR array?

Re: Have sub routine handle file OR array?

am 18.12.2007 16:31:06 von Michele Dondi

On Sat, 15 Dec 2007 10:49:19 -0500, Fred wrote:

>In the code snippet below a file is opened and processed one line at a
>time. Is there a way this same subroutine could handle an array OR
>file,depending what is passed to it? For example, if all the lines in
>$file were read into an array named @myfile. Then it would read "while (
>@myfile ) {".

You could use an *iterator* object. Just let the constructor accept
either a filehandle, or a plain list (or an arrayref) or... whatever
you like!


Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^ ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER 256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,