Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: Using elements to search a file

by GC (Initiate)
on May 06, 2009 at 17:55 UTC ( #762339=note: print w/replies, xml ) Need Help??


in reply to Re: Using elements to search a file
in thread Using elements to search a file

Example:

User input: 11111

Will find this line in the first file: 11111 1010101 1010102 1010103 1010104 1010105 1010106

Which puts: 1010101 1010102 1010103 1010104 1010105 1010106 into an array.

Each of those will be used as search criteria in the second file, the irst should read this line: 1010101 Address Line 1 ,Address Line 2 ,Phone Number ,Fax Number,

So I can print the information.

If that makes sense.

Replies are listed 'Best First'.
Re^3: Using elements to search a file
by jpearl (Scribe) on May 06, 2009 at 18:23 UTC
    That does make sense. However, I think your problem is in this loop:
    while ( <$contin> ) { if ( $contractors =~ m/^$string(.*)/ ) { my @results = split(m#\s+#, $1); print br; print @results; } } close( $contin ); }
    Specifically I think you're running into a problem at
    if ( $contractors =~ m/^$string(.*)/ )
    It looks like what you want to be doing is matching every line in $contin against your current $contractor where what you're actually doing is matching $contractor against your regex ^$string(.*) Try changing the above regex in the while loop to have something like
    while ( <$contin> ) { if ($_ =~ m/^$contractor(.*)/) { my @results = split(m#\s+#, $1); print br; print @results; } } close( $contin ); }
      That gets me a whole lot closer. It's spitting out every line in the file, but at least it's giving me something I can work with.

      Thanks for getting me out of that hole, I appreciate the help.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2022-05-27 22:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (98 votes). Check out past polls.

    Notices?