Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Difficult problem...

errodrerrodr Member Posts: 5
I have a difficult problem, which I'm sure someone here will be

able to figure out quickly.

Problem:

I have two files (.txt) each file contains a list of page titles.

What I need to do is take File A (the Master list) remove from

it page titles that appear in File B (the a page title subset).

Basically I need to take the page titles that appear in File B

and remove those titles from File A.

I have tried this, and it simply spits out File A with no changes.
--------------------------------------------------------------------------------
Code
--------------------------------------------------------------------------------

open(FILEB,"FileB.txt")||die;
while(){
$file1hash{$_}=1;
}
close(FILEB);

open(OUTPUTFILE,">new_report.txt")||die;

open(FILEA,"FileA.txt")||die;

while(){
print OUTPUTFILE $_ unless defined($file1hash{$_});
}
close(FILEA);close(OUTPUTFILE);

--------------------------------------------------------------------------------

Thanks a lot...

Comments

  • heeroyuyheeroyuy Member Posts: 125
    If the tittles will be seperated by lines, why don't you just pop the file into an array and do something like the following(not it may or may not be simpler to do pattern searching, but I don't recall offhand, because I do not use regex that often)

    [code]
    @filea=;
    @fileb=;
    $i=0;
    $b=0;
    while (defined($filea[$i]) && defined($fileb[$b])) {
    if ($filea[$i] eq $fileb[$b]) {
    #DO ALL HANDLING IF TWO LINES ARE EQAL
    }
    else {
    $i++;
    }

    }
    [/code]

    That should work, tell me if it doesn't, then just modify b whenever a is undefined, i think the rest is self explanatory

    -----------------------
    [RED]Heero Yuy
    Perl Board Moderator
    Perl Semi-Expert[/RED]

  • errodrerrodr Member Posts: 5
    : If the tittles will be seperated by lines, why don't you just pop the file into an array and do something like the following(not it may or may not be simpler to do pattern searching, but I don't recall offhand, because I do not use regex that often)
    :
    : [code]
    : @filea=;
    : @fileb=;
    : $i=0;
    : $b=0;
    : while (defined($filea[$i]) && defined($fileb[$b])) {
    : if ($filea[$i] eq $fileb[$b]) {
    : #DO ALL HANDLING IF TWO LINES ARE EQAL
    : }
    : else {
    : $i++;
    : }
    :
    : }
    : [/code]
    :
    : That should work, tell me if it doesn't, then just modify b whenever a is undefined, i think the rest is self explanatory
    :
    : -----------------------
    : [RED]Heero Yuy
    : Perl Board Moderator
    : Perl Semi-Expert[/RED]
    :
    :


    Thanks. I figured out what was wrong with the code that I had
    posted... I forgot to strip the spaces, once I did that, it worked fine.

    Thanks for your help...
  • Andre YoungAndre Young USAMember Posts: 0

    _ { http://forcoder.org } free video tutorials and ebooks about \ Visual Basic .NET, Java, MATLAB, Go, Objective-C, PHP, R, Python, C++, Delphi, C, Ruby, Swift, Assembly, C#, Scratch, Perl, Visual Basic, PL/SQL, JavaScript Bash, Clojure, Transact-SQL, ABAP, SAS, Erlang, Scala, ML, FoxPro, Logo, Julia, Hack, Alice, Lua, VBScript, D, F#, Scheme, Kotlin, Apex, Dart, Ada, Prolog, Lisp, Rust, Awk, COBOL, Crystal, Fortran, LabVIEW \ ______

Sign In or Register to comment.