Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: Altering data files

by systems (Pilgrim)
on Oct 12, 2006 at 16:16 UTC ( #577895=note: print w/replies, xml ) Need Help??

in reply to Altering data files

Below is my attempt. Some assumptions are made the most important is that "" "seq_name" will be one line below "StrCatDone". Also note I am a Perl newbie, so the code below is not of good quality. Any my logic is.
  1. Read the file into an array.
  2. Find the array index where you find: "StrCatDone" "1". Using the for(;;) loop.
  3. Modify the array element of the next index hence the ++$i.
  4. write the array back to the file.
use strict; use warnings; my $file = shift @ARGV; open (my $fh1, $file) or die "Can't open file \"$file\", $!"; my @txt = <$fh1>; close $fh1; my $newtext = '"seq_name" "sequence.V6.0"'; my $i; for ($i=0; $i <= $#txt; $i++) { last if $txt[$i]=~ m/"StrCatDone" "1"/; #print $txt[$i]; } $txt[++$i]="$newtext\n"; open (my $fh2,">$file") or die "Can't open file \"$file\", $!"; print $fh2 @txt;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://577895]
[Discipulus]: see you monks! flying to greece!
[Corion]: Oh, cool! Have fun Discipulus!

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (10)
As of 2018-06-25 18:18 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (128 votes). Check out past polls.