Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: Threading two text files

by ww (Archbishop)
on May 14, 2013 at 23:33 UTC ( #1033582=note: print w/replies, xml ) Need Help??

in reply to Threading two text files

If you're going to use seek, read the documentation, the first graf of which explains how to increment the position:
        Sets FILEHANDLE's position, just like the "fseek" call of
        "stdio". FILEHANDLE may be an expression whose value gives the
        name of the filehandle. The values for WHENCE are 0 to set the
        new position *in bytes* to POSITION; 1 to set it to the current
        position plus POSITION; and 2 to set it to EOF plus POSITION,
        typically negative. For WHENCE you may use the constants
        "SEEK_SET", "SEEK_CUR", and "SEEK_END" (start of the file,
        current position, end of the file) from the Fcntl module.
        Returns 1 on success, false otherwise.

Assuming your really intend to do something like this:

#!/usr/bin/perl use 5.016; use Data::Dumper; #1033562 (and id num_qqq.txt, idnum_exp.txt) =head file 1033562_exp.txt exp.txt 0 foo 3 bar 1 table 3 quux 3 fail 2 file 1033562_qqq.txt qqq.txt 0 fail 2 nope 1 foo 3 insert 1 bar 1 quux 3 table 3 tambourine 2 fred 14 =cut open(INDB, "1033562_exp.txt") or die "Can't open exp file, $!"; open(QQQ, "1033562_qqq.txt") or die "Can't open data file, $!"; my (@search, @therecs); while(<INDB>) { my $search = $_; chomp($search); say "\$search at Ln28: $search"; push @search, $search; seek(INDB, 0, 0); } print "\n\n"; while(<QQQ>) { my ($ma,$id); my $therec = $_; say "Both elements of \$therec at Ln36: $therec"; chomp($therec); ($ma,$id ) = split(/\t/, $therec); push @therecs, (" $ma " . "| $id |"); my $Qpos=tell QQQ; say "\n\t POS in QQQ: $Qpos \n"; } say "\n \t array search next:"; say Dumper @search; say "\n \t Array @therecs next:"; say Dumper @therecs;

Identifying the matches is left as an exercise to the SOPW. %hash might be an approach; so too might what you originally suggest but didn't implement-- walking the arrays in parallel. Both are well documented in threads here in the Monastery.

If you didn't program your executable by toggling in binary, it wasn't really programming!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1033582]
and a log crumbles through the grate...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2018-05-24 18:42 GMT
Find Nodes?
    Voting Booth?