tomy $this = <$files[$num]>;
should work.my $handle = $files[$num]; my $this = <$handle>;
By the way, you read one line too many. Your while test should be $totalLines < $wantedLines.
UPDATE: Thanks to Tanktalus for pointing me to the documentation. I/O Operators has this to say:
If what's within the angle brackets is neither a filehandle nor a simple scalar variable containing a filehandle name, typeglob, or typeglob reference, it is interpreted as a filename pattern to be globbed, and either a list of filenames or the next filename in the list is returned, depending on context. This distinction is determined on syntactic grounds alone. That means <$x> is always a readline() from an indirect handle, but <$hash{key}> is always a glob(). That's because $x is a simple scalar variable, but $hash{key} is not--it's a hash element. Even <$x > (note the extra space) is treated as glob("$x "), not readline($x).
In reply to Re: reading from an arbitrary number of files using anonymous file handles
by JadeNB
in thread reading from an arbitrary number of files using anonymous file handles
by downer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |