in reply to compare lines within a file
As your input file looks a lot like a variant on CSV (with spaces and newlines as delimiters), I would suggest using one of the modules for parsing these types of files off of . My usual choice is Text::CSV, but the search results for CSV will give you an idea of how many solutions are out there for this parsing problem. The above module will generate an array of arrays for you - let us know if you have difficulty dealing with Perl references.
Your code may end up looking something like this (adapted from the documentation):
#!/usr/bin/perl use strict; use warnings; use Text::CSV; my @result; my $csv = Text::CSV->new ( { sep_char => ' ' } ) # should set binary +attribute. or die "Cannot use CSV: ".Text::CSV->error_diag (); open my $fh, "<", "test.csv" or die "test.csv: $!"; while ( my $row = $csv->getline( $fh ) ) { if ($row->[0] =~ m{\QHWUSI-EAS95L_0025_FC:3:1:5232:1082#0/\E}) { if (@result) { $result[1] = $row->[3]; } else { $result[0] = $row->[2]; } } } printf "%s\t%s\n", @result; $csv->eof or $csv->error_diag(); close $fh;
As you did not wrap your input text in <code> tags, it's possible the files were mangled during posting. For example, if your file is actually tab delimited, you would need to specify "\t" as your delimiter, not " ".
Update: Fixed typo in code
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: compare lines within a file
by garyboyd (Acolyte) on Mar 10, 2011 at 08:32 UTC | |
by garyboyd (Acolyte) on Mar 10, 2011 at 08:37 UTC | |
by kennethk (Abbot) on Mar 10, 2011 at 15:29 UTC | |
by garyboyd (Acolyte) on Mar 11, 2011 at 13:56 UTC | |
by kennethk (Abbot) on Mar 11, 2011 at 23:27 UTC | |
|