Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3609834
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:40:39+00:00 2026-05-18T21:40:39+00:00

I’ve just written my first Perl module and am having trouble getting it to

  • 0

I’ve just written my first Perl module and am having trouble getting it to work with a script I produced also. Here is the error that the Perl interpreter displays when I attempt to run the script that is using my newly created module.

Error message:

scraper_tools_v1.pm did not return a true value at getYid.pl line 5.
BEGIN failed--compilation aborted at getYid.pl line 5.

scraper_tools_v1.pm is the Perl module which I have written and getYid.pl is the Perl script which attempts to utilize the scraper_tools_v1.pm module.

Here is the code for the scraper_tools_v1.pm file:

#!/usr/bin/perl

package scraper_tools_v1;

use strict;
use warnings;
use WWW::Curl::Easy;

# Note this function expects a single parameter which should be in the form of a URL

  sub getWebPage($)
  {
    # Setting up the Curl parameters
    my $curl = WWW::Curl::Easy->new; # create a variable to store the curl object

    # A parameter set to 1 tells the library to include the header in the body output.
    # This is only relevant for protocols that actually have headers preceding the data (like HTTP).
    $curl->setopt(CURLOPT_HEADER, 1);

    # Setting the target URL to retrieve with the passed parameter
    $curl->setopt(CURLOPT_URL, @_);

    # Declaring a variable to store the response from the Curl request
    my $response_body = '';

    # Creating a file handle for CURL to output to, then redirecting our output to the $response_body variable
    open(my $fileb, ">",\$response_body) or die $!;
    $curl->setopt(CURLOPT_WRITEDATA, $fileb);

    # getting the return code from the header to see if the GET was successful
    my $return_code = $curl->perform;

    # capturing the response code from the GET request in the HTTP header, i.e... 200, 404, 500, etc...
    # 200 is success
    my $response_code = $curl->getinfo(CURLINFO_HTTP_CODE);  

    # if the return code is zero than the request was a success
    if ($return_code == 0)
    {    
      # A little debug output to keep you informed
      print ("Success ". $response_code.": ".@_."\n");

      # return whatever was contained on the web page that we just got using a GET
      return $response_body;
    }

    else
    {
      print ("Failure ". $response_code.": ".@_."\n");
    }

    close($fileb); # close the file-handle

    }

And here is the getYid.pl script which attempts to use the above module

#!/usr/bin/perl

use strict;
use warnings;
use scraper_tools_v1;

my %cat_links; # Hash that stores categories and their numbers (ID's)
my $web_page = scraper_tools_v1->getWebPage("http://something.com/categoryindex.aspx");

my @lines = split(/\n/, $web_page);

foreach my $line (@lines)
{
  chomp($line);

  if ($line =~ /<option value=\"{1}(.+)\">(.+)<\/option>/)
  {
    my $num = $1;
    my $desc = $2;
    $desc =~ s/\s+&amp;\s+/ & /;
    $cat_links{$desc} = $num;
  }
}

my @allTargetUrls; # make a new array to store all the links we need to extract listings from
$web_page = '';    # Reset this variable so we can reuse it.

my $totalNumberOfListings = 0;

foreach my $key (keys %cat_links)
{
  my $target = "http://something.com/categorydetail.aspx?id=$cat_links{$key}&exact_phrase=0";
  $web_page = scraper_tools_v1->getWebPage($target);

  @lines = split(/\n/, $web_page);

  foreach my $line (@lines)
  {
    my $pages;
    chomp($line);
    if ($line =~ /We found (\d) listings for your search\./)
    {
          my $listingsInCat = $1;
      print ("$cat_links{$key}, $listingsInCat");
      $totalNumberOfListings += $listingsInCat;
    }
    if ($line =~ /Page 1 of (\d)/)
    {
       $pages = $1;
    }

    for (my $i = 1; $i <= $pages; $i++)
    {
      #build the target urls
      my $pageUrl = "http://something.com/categorydetail.aspx?id=$key&search=&exact_phrase=True&city=&state=&zipcode=&page=$i";
      push(@allTargetUrls, $pageUrl);
    }
  }

  print("Total number of listings = ".$totalNumberOfListings);
} 

Any help in resolving this issue would greatly be appreciated and please note that I have tested both files independently for interpreter errors and found nothing. Thanks to all for taking a look.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T21:40:40+00:00Added an answer on May 18, 2026 at 9:40 pm

    When you write a Perl module, you should always end the file with the line

    1;
    

    Perl executes code at the module level when the module is imported. If you don’t return a true value (1 is true), then you’ll get the error you describe. Essentially, Perl is informing you that the initialisation code in your module didn’t succeed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I've got a string that has curly quotes in it. I'd like to replace
I want use html5's new tag to play a wav file (currently only supported
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a JSP page retrieving data and when single or double quotes are
I'm looking for suggestions for debugging... If you view this site in Firefox or
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.