Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: How to make a copy of filehandle

by jwkrahn (Monsignor)
on Apr 09, 2013 at 08:46 UTC ( #1027681=note: print w/replies, xml ) Need Help??


in reply to How to make a copy of filehandle

my $filename = $ARGV[0]; my $nb_lines = 0; open (my $file, $filename) or die "Can't open '$filename': $!"; my $hdl_sauv; while (<$file>) { $nb_lines++ ; if ($nb_lines == 5) { open ($hdl_sauv, "<",$file) || die "cannot open $file\n"; } } my $saved_line = <$hdl_sauv>; print "$saved_line\n";

It looks like you want something like this:

my $filename = $ARGV[ 0 ] or die "Usage: $0 file\n"; open my $file, $filename or die "Can't open '$filename': $!"; while ( <$file> ) { last if $. == 5; } print;


I am trying to make a copy of the filehandle, that is *not* sharing file position.

Your code does not make a copy of the filehandle, nor does it share the file position.    It tries to open the previous filehandle as if it were a file name.    If you had opened $filename instead of $file you would have a different filehandle for the same file, but that still wold not solve your problem as it would be pointed at the beginning of the file.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1027681]
help
Chatterbox?
[Corion]: Oof - "Anyway, if it is not obvious, please keep this discussion entirely confidential for now.", as seen on a public mailing list ;)
[Discipulus]: uh no choroba.. i do not practice much with online putyour image sites:can you suggest one (that possibly remove the pic after few days)?
[choroba]: Corion a bug report?
[choroba]: I have no idea :-( I used to post to photobucket.com, but they don't seem to feature "private" pictures in the free version now
[Discipulus]: dazz i'm not an experts but i think it would be possible
[Corion]: dazz: I think Image::Magick can "read" from an in-memory filehandle
[Corion]: choroba: No, some general admin discussion of how to handle (company) user accounts
[Discipulus]: might be it is necessary to pass the pic data like MIME::Base64:: encode( data..
[Discipulus]: if you have a jpeg data: or as wise Corion said IM ca n read directly your handle

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (10)
As of 2017-03-27 07:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (317 votes). Check out past polls.