Note that there are some explanatory texts on larger screens.

plurals
  1. POPerl - Breaking a variable from the input into two for the url
    primarykey
    data
    text
    <p>I'm loading data from a .txt for the purposes of scraping. However, the URL requires that I break that variable up and do +/- 2 to it. For example, if the value is 2342, I need to create 2340 and 2344 for the purposes of the URL. </p> <p>I took a guess at how to break it up:</p> <pre><code> $args{birth_year} = ($args{birth_year} - 2) . '-' . ($args{birth_year} + 2); </code></pre> <p>How do I then put it in the URL?</p> <p>Here's the relevant part of the code:</p> <pre><code> use strict; use warnings; use WWW::Mechanize::Firefox; use Data::Dumper; use LWP::UserAgent; use JSON; use CGI qw/escape/; use HTML::DOM; open(my $l, 'locations2.txt') or die "Can't open locations: $!"; while (my $line = &lt;$l&gt;) { chomp $line; my %args; @args{qw/givenname surname birth_place birth_year gender race/} = split /,/, $line; $args{birth_year} = ($args{birth_year} - 2) . '-' . ($args{birth_year} + 2); my $mech = WWW::Mechanize::Firefox-&gt;new(create =&gt; 1, activate =&gt; 1); $mech-&gt;get("https://familysearch.org/search/collection/index#count=20&amp;query=%2Bgivenname%3A$args{givenname}20%2Bsurname%3A$args{surname}20%2Bbirth_place%3A$args{birth_place}%20%2Bbirth_year%3A1910-1914~%20%2Bgender%3A$args{gender}20%2Brace%3A$args{race}&amp;collection_id=2000219"); </code></pre> <h3>For Example</h3> <p><em>Input is:</em></p> <pre><code>Benjamin,Schuvlein,Germany,1912,M,White </code></pre> <p><em>Desired URL is:</em></p> <p><a href="https://familysearch.org/search/collection/index#count=20&amp;query=%2Bgivenname%3ABenjamin%20%2Bsurname%3ASchuvlein%20%2Bbirth_place%3AGermany%20%2Bbirth_year%3A1910-1914~%20%2Bgender%3AM%20%2Brace%3AWhite&amp;collection_id=2000219" rel="nofollow">https://familysearch.org/search/collection/index#count=20&amp;query=%2Bgivenname%3ABenjamin%20%2Bsurname%3ASchuvlein%20%2Bbirth_place%3AGermany%20%2Bbirth_year%3A1910-1914~%20%2Bgender%3AM%20%2Brace%3AWhite&amp;collection_id=2000219</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload