[Fwd: How can I get the last element on each line in a text file] 
Author Message
 [Fwd: How can I get the last element on each line in a text file]

Hi:
Making a temporary copy as suggested in the perlfaq5 to write/overwrite the
destination value in the
same text file did not help and hence I am trying to push the modified last
element back to the file as below, but the input text file does not get updated
with the modified information
How can I write back to the same text file(array) the modification I made to it?

use File::Basename;

$file=$ARGV[0];
open(INFO,"<$file") || die "Cannot open $file: $!";


  {
   #$/ = "";
   next if $a =~ /^#/;
   ($first,$last) = split(/[|]/,$a);
   $src = basename($first);
   $dir = dirname($last);

   $tail=$parts[$#parts];
   $tail=$src;
   $last = $dir . "/" . $tail;

the file.
   }
close <INFO>;
exit;

Thank You
Nishi.

Quote:

> Also, for each record in the text file, after modifying the destination part
> of each record, alongwith
> printing out the modified destination value , can I also write/overwrite the
> destination value in the
> same text file?

> Thank You
> Nishi






> > > > My text file contains n number of lines like:
> > > > c:/winnt/a.txt
> > > > c:/abc/c.txt
> > > > c:/def/def.pl
> > > ...
> > > > My perl script reads the text file into an array.
> > > > How can I extract just the last element on each line and do some
> > > > processing on it? e.g. in the above example, i would like to extract
> > > > a.txt from first line, c.txt from the second line and def.pl from the


> > >    next unless m|^.*/(.+)$|;

> > or:

> > next unless m|/([^/]+)$|;

> > >    doYourProcessing( $1 );
> > >    # or just use $1, or assign $1 to something...
> > > }

> > > prints:
> > > GOT: a.txt
> > > GOT: c.txt
> > > GOT: def.pl
> > > using your examples

> > > P
> > --
> > Michael Budash
> > Michael Budash Consulting




Sun, 11 Jul 2004 20:23:38 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. [Fwd: How can I get the last element on each line in a text file]

2. How can I get the last element on each line in a text file

3. How can I get the last element on each line in a text file

4. pull out last line in a text file

5. getting the last element position in multi dimentional array

6. getting next line in text file

7. Getting a line from a text file into an array

8. Getting info of file last update

9. better way of getting the last modified file?

10. WinNT: getting File Last Modified data from outside current directory

11. Fwd: Re: My Last Words on =- vs comma

12. Search a file (line by line) for String/text

 

 
Powered by phpBB® Forum Software