in reply to desire to pass file handles by value
The output is still -#!/usr/bin/perl -w use strict; sub find { local *IN = shift; my $find_me = shift; my $count = 0; # duplicate existing file handle open F2, '<&', *IN or die "Can not duplicate file handle"; my $tell = tell(F2); while (<F2>) { $count++ if (/$find_me/); } return "count: $count tell: $tell\n"; close F2; } open OUT, '>', 'tmp.txt' or die "$!\n"; print OUT while (<DATA>); close OUT or die "$!\n"; open IN, 'tmp.txt' or die "$!\n"; print find( *IN, 'a' ); print find( *IN, 'a' ); print find( *IN, 'd' ); print find( *IN, 'e' ); __DATA__ a a a c d e
That didn't work either! Ok, that taught me a lession - my assumption on the duplicated file handle could be wrong. I need some re-education.#count: 3 tell: 0 #count: 0 tell: 13 #count: 0 tell: 13 #count: 0 tell: 13
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: desire to pass file handles by value
by mandog (Curate) on Nov 07, 2003 at 03:47 UTC | |
by jdporter (Paladin) on Nov 07, 2003 at 05:44 UTC | |
by ysth (Canon) on Nov 07, 2003 at 09:52 UTC | |
by jdporter (Paladin) on Nov 07, 2003 at 16:29 UTC | |
Re: Re: desire to pass file handles by value
by nevyn (Monk) on Nov 07, 2003 at 09:11 UTC | |
Re: Re: desire to pass file handles by value
by Anonymous Monk on Nov 07, 2003 at 07:27 UTC |