Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^4: comparing file contents

by Anonymous Monk
on Nov 22, 2011 at 16:23 UTC ( #939486=note: print w/ replies, xml ) Need Help??


in reply to Re^3: comparing file contents
in thread comparing file contents

I have two files namely ICD-Codes-text which is tab format and other file named female.txt which has been split word by word . i need to compare the contents of female1.txt to ICD-codes file 0th array values. If there is a match then the matched value in female1.txt should be replaced with ICD-code files corresponding 1st array value. I am a beginner in PERL. I tried to write some code but i do not know where am going wrong or its completely wrong. Help me with this please

#!/usr/bin/perl print "reading 'ansvarig_vardenhet_utf8.txt'\n"; open(WIN, "icd-10-codes.txt"); while($line = <WIN>) { @columns = split(/\t/, $line); #print "$columns[1]"; foreach my $value (@columns) { #print "$value\n" } } close(WIN); print "reading 'ansvarig_vardenhet_utf8.txt'\n"; open(IN, "female1.txt"); while($line = <IN>) { %col = split(/ /, $line); #print "$columns[1]\n"; foreach my $val (%col) { if($val == $columns[0]){ $val =~ s/$val/$columns[1]/g; print IN ">>$val\n"; } } } close(IN);

file samples

ICD.codes-text z988 Z98.8 - Andra specificerade postoperativa tillstånd z99 Z99 - Beroende av maskinella och andra hjälpmedel som ej klassificeras annorstädes z990 Z99.0 - Beroende av aspirationshjälpmedel z991 Z99.1 - Beroende av respirator z992 Z99.2 - Beroende av njurdialys z993 Z99.3 - Beroende av rullstol z998 Z99.8 - Beroende av annan specificerad utrustning och andra specificerade hjälpmedel z999 Z99.9 - Beroende av icke specificerade maskinella och andra hjälpmedel

female1.txt

patient has been admitted to the hospital for having infection on the recently operated right leg. w0609 w0609 w0609 w0609 w0609 w0609


Comment on Re^4: comparing file contents
Download Code
Re^5: comparing file contents
by Util (Priest) on Nov 22, 2011 at 17:40 UTC

    Please look at how your file samples appear to the rest of us; with no line breaks, we cannot tell what should be on line one of the file, vs line two, etc.

    Then, please edit your post so that lines of data do not all run together.

    If you cannot edit the post, (because you did not log in when you posted it), then add another post with just the two data files.

    When you post anything on this site, there is a notice, in bold, directly below the "preview" button:

    Put <code> </code> tags around your code and data!
    (The notice does not appear then you edit an existing post, but probably *should* appear.)

    We want to help you. You just are not giving us all the information we need to help you.

      I have two files namely ICD-Codes-text which is tab format and other file named female.txt which has been split word by word . i need to compare the contents of female1.txt to ICD-codes file 0th array values. If there is a match then the matched value in female1.txt should be replaced with ICD-code files corresponding 1st array value. I am a beginner in PERL. I tried to write some code but i do not know where am going wrong or its completely wrong. Help me with this please

      #!/usr/bin/perl print "reading 'ansvarig_vardenhet_utf8.txt'\n"; open(WIN, "icd-10-codes.txt"); while($line = <WIN>) { @columns = split(/\t/, $line); #print "$columns[1]"; foreach my $value (@columns) { #print "$value\n" } } close(WIN); print "reading 'ansvarig_vardenhet_utf8.txt'\n"; open(IN, "female1.txt"); while($line = <IN>) { %col = split(/ /, $line); #print "$columns[1]\n"; foreach my $val (%col) { if($val == $columns[0]){ $val =~ s/$val/$columns[1]/g; print IN ">>$val\n"; } } } close(IN);

      file samples

      ICD.codes-text

      z988 Z98.8 - Andra specificerade postoperativa tillstånd z99 Z99 - Beroende av maskinella och andra hjälpmedel som ej klassi +ficeras annorstädes z990 Z99.0 - Beroende av aspirationshjälpmedel z991 Z99.1 - Beroende av respirator z992 Z99.2 - Beroende av njurdialys w0609 W06.09 - Fall från säng-bostad-ospec aktiviteter z993 Z99.3 - Beroende av rullstol z998 Z99.8 - Beroende av annan specificerad utrustning och andra sp +ecificerade hjälpmedel z999 Z99.9 - Beroende av icke specificerade maskinella och andra hj +älpmedel

      female1.txt

      patient has been admitted to the hospital for having infection on the +recently operated right leg. w0609 w0609 w0609 w0609 w0609 w0609

      I hope i have changed it as required. If not please let me know i will try to change further. thanks for your time and effort to help me correct my problems. Thanks for your help in advance

        I hope i have changed it as required.

        Your latest post appears properly formatted... but next time, please do so as an edit of the mal-formatted post (and be sure to add a note that you've done so) rather than creating a redundant node.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://939486]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2014-12-23 01:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (133 votes), past polls