문제

I'm making a script that extracts a url from a tweet. In running the script and out putting it into an array it out putted about 30 urls only one of which is the correct one. So I used a grep with the first part of the url I wanted from the array and got the 'found it' output.

my $tco = "http://t.co";

if (grep /$tco/, @links) {
    print "found it\n";
}

I was wondering if I could takw that line what started with http://t.co and make that line into a variable ex:

$extracted_url = 'what I found in the array'

How would I go about doing this? Thank you in advance!, Brett

도움이 되었습니까?

해결책

Try this:

my @found = (grep /\Q$tco/, @links);
for my $url (@found) {
    print "found $url\n";
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top