Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Hi Lakssreedhar
Use a 2D array to read a file column wise. Then adopt the folowing steps :

1. count the number of lines of your file.
2. Use some regular expression to split the file with respect to the column delimiters i.e tab in your case . Thus build the 2D array.
3. Use a sub routine to get all the values of the 9th column and push them in an array.
4. Process the array to look where at which index I is preceded by O. Find those indexes.
5. open your data file again and using the 2D matrix just replace those positions .
The following code could be a bit help to you

my @matrix; my $row = 0; # count no. of lines open(DATA, "< data.txt"); my @lines = <DATA>; close(DATA); my $c = @lines; open(DATA, "< data.txt"); push @{$matrix[$row++]}, split while <DATA>; dd @matrix; &colprint(\@matrix); close(DATA); my @arrayOfninth_col; sub colprint { my $matrix_ref = shift; for (1 .. $c) { print "$matrix_ref->[$c-1][9] \n"; my $value = $matrix_ref->[$c-1][9]; push @arrayOfninth_col , $value; } # process the array @arrayOfninth_col for indexes }

In reply to Re: search and replace a word in a column by ghosh123
in thread search and replace a word in a column by lakssreedhar

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2022-08-09 04:53 GMT
Find Nodes?
    Voting Booth?

    No recent polls found