CodingNovice
CodingNovice

Reputation: 103

How can I generate an SQL where clause from a filtered list of lines in a file?

#!/usr/bin/perl

use strict;
use warnings;
use LWP::Simple;
use Regexp::Common qw/net/;

getstore("https://<redacted>", "ips.txt");

open(my $input, "<", "ips.txt");

while (<$input>) {

print $1, "\n" if /($RE{net}{IPv4})/;

}

Hello all,

I've created a perl script above that will pull down IP addresses from a website using the API (redacted), and store the IP addresses in a text file. The text file looks like this (but with many more IP addresses):

1.55.227.59
5.1.80.127 
5.1.80.235

I am attempting to figure out how to add a line to make the script print an output to look like this for all IP addresses in the file:

("1.55.227.59" OR "5.1.80.127" OR "5.1.80.235")

So far, attempts have been unsuccessful. Anyone have any ideas on how to accomplish this? Help would be greatly appreciated.

Upvotes: 0

Views: 53

Answers (1)

Matt Jacob
Matt Jacob

Reputation: 6553

use strict;
use warnings;

use Regexp::Common qw/net/;

print '(', join(' OR ', map { chomp; qq{"$_"} } grep { /$RE{net}{IPv4}/ } <DATA>), ")\n";

__DATA__
1.55.227.59
5.1.80.127
5.1.80.235

Output:

("1.55.227.59" OR "5.1.80.127" OR "5.1.80.235")

Upvotes: 1

Related Questions