Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: extract line

by mtmcc (Hermit)
on Jul 20, 2013 at 17:26 UTC ( [id://1045457]=note: print w/replies, xml ) Need Help??


in reply to extract line

I'm not sure where the "ROCKER ARM ASSEMBLIES AND GROUPS" is coming from, but if I understand what you're trying to do, I think you might be over complicating it.

Something like this should work:

#! /usr/bin/perl use strict; use warnings; my $serialNumbers = $ARGV[0]; my $partNumbers = $ARGV[1]; my @line; my %partNumber; open (my $fileTwo, "<", $partNumbers); while (<$fileTwo>) { chomp; $partNumber{$_} = 1; } open (my $fileOne, "<", $serialNumbers); while (<$fileOne>) { @line = split (":", $_); print STDERR "$_" if exists $partNumber{$line[0]}; }

I hope that helps.

Replies are listed 'Best First'.
Re^2: extract line
by lallison (Novice) on Jul 20, 2013 at 21:10 UTC
    Thank you, I will give this a try. This file has over a million lines and is running very slow. Is there a quick way to control the buffering.
      I'm afraid not that I can see. I think the split probably slows it down, but I don't think it's avoidable. If you do find a faster way, please let me know!

      Best of luck.

Re^2: extract line
by lallison (Novice) on Jul 20, 2013 at 22:59 UTC

    Not very familiar with argv. Where am I giving the program my file names? I am also printing to a outfile. I tried it as written and receive an uninitialized value $partNumbers but believe this is due to the filename.

      $ARGV[0] is the first argument on the command line (name of file with longer 'serial numbers'), and $ARGV[1] is the second argument on the command line (file containing the integers).

      To run it:  script.pl serialnumbers.txt integers.txt

      To print to a third file, add this somewhere before the second while loop:

      open (my $output, ">", 'nameOfOutputFile.txt');

      and change print STDERR to print $output.

      I hope that works!
        What does the line $partNumber{$_} = 1; d?

        It runs but the output is incorrect. When I print $partNumber{$_} I get 1, the values assigned instead of the part number

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-25 20:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found