[EMAIL PROTECTED] wrote:
> 
> Hello...

Hello,

> I am a beginner in Perl an I have a trouble, I am sure you are going to
> help me.
> 
> Suppose I have a file with, for example, 10 lines, every one composed by
> a inferior value and a superior value and a string. Every inferior value
> is equal to superior value of the before line. On the other hand, I have
> other file with, for example, 1000 lines with a only column of values and
> I want to create another column here with the value of the string if the
> value of the column is between two values (inferior-superior) of the same
> line in the first file, I mean, it would be several consecutive lines
> with the value of the string of the line 1 of first file, after, several
> consecutive lines with the value of the string of the line 2, and so on.
> 
> How can I do that?, I open the files but I am not sure how to do it.


If I understand you correctly the following example program should give you some ideas:

#!/usr/bin/perl
use warnings;
use strict;

use Inline::Files;

my @strings;
while ( my $line = <FILE1> ) {
    chomp $line;
    my ( $inferior, $superior, $string ) = split ' ', $line, 3 or next;
    push @strings, [ $superior, $string ];
    }

# ensure correct order of @strings
@strings = sort { $a->[ 0 ] <=> $b->[ 0 ] } @strings;

while ( my $num = <FILE2> ) {
    chomp $num;
    for my $str ( @strings ) {
        if ( $num < $str->[ 0 ] ) {
            print "$num\t$str->[1]\n";
            last;
            }
        }
    }

__FILE1__
1   20  string one
20  35  string two
35  47  string three
47  99  string four

__FILE2__
5
18
19
20
21
22
80
99999


Produces the following output:

5       string one
18      string one
19      string one
20      string two
21      string two
22      string two
80      string four



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to