reopen the file

reopen the file

am 26.12.2007 11:05:11 von vijay

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

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

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


Th@nks

Re: reopen the file

am 26.12.2007 11:08:12 von Peter Makholm

"vijay@iavian.com" writes:

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

Read the documentation for the seek function.

//Makholm

Re: reopen the file

am 26.12.2007 11:46:00 von vijay

On Dec 26, 3:08 pm, Peter Makholm wrote:
> Read the documentation for the seek function.
>
> //Makholm

Kool , It works

Re: reopen the file

am 27.12.2007 20:46:50 von Ben Morrow

Quoth "vijay@iavian.com" :
> 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(){
> 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(){
> #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

Re: reopen the file

am 27.12.2007 21:02:11 von Joost Diepenmaat

Ben Morrow writes:

> 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.