reopen the file

V

vijay

open(MAPFILE, $FTP_MAPFILE);
while(<MAPFILE>){
chop;
($user,$file) = split /=/;
if(uc($user) eq uc($userid)){
push(@files,$file);
}
}
close(MAPFILE);

open(MAPFILE, $FTP_MAPFILE);
while(<MAPFILE>){
#do something;
}

In the above code i open the file twice to read . How do i do
something without reopening the file


Th@nks
 
B

Ben Morrow

Quoth "[email protected] said:
open(MAPFILE, $FTP_MAPFILE);

Use three-arg open.
Use lexical filehandles.
Check the return value of open.

open(my $MAPFILE, '<', $FTP_MAPFILE)
or die "can't open '$FTP_MAPFILE': $!";
while(<MAPFILE>){
chop;

Don't use chop, use chomp instead.
($user,$file) = split /=/;

Why aren't you using strict?
if(uc($user) eq uc($userid)){

It's generally better to normalise case with lc than with uc. Unicode
defines three cases (upper, lower and title), and while upper->lower and
title->lower are well-defined, title->upper isn't.
push(@files,$file);
}
}
close(MAPFILE);

open(MAPFILE, $FTP_MAPFILE);
while(<MAPFILE>){
#do something;
}

In the above code i open the file twice to read . How do i do
something without reopening the file

See perldoc -f seek.

Ben
 
J

Joost Diepenmaat

Ben Morrow said:
It's generally better to normalise case with lc than with uc. Unicode
defines three cases (upper, lower and title), and while upper->lower and
title->lower are well-defined, title->upper isn't.

Now that's a good suggestion I'd never heard.

Cheers,

Joost.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,208
Messages
2,571,082
Members
47,683
Latest member
AustinFairchild

Latest Threads

Top