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

  • SEARCH
  • Home
  • 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 8895027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:39:50+00:00 2026-06-14T23:39:50+00:00

So, I’m new to Perl. I’m attempting to create a recursive subroutine. The logic

  • 0

So, I’m new to Perl. I’m attempting to create a recursive subroutine. The logic seems simple:

sub directory_tree
{
    my $sth = $dbh->prepare("
        SELECT id, org_id, name
        FROM media_directories
        WHERE
            org_id = ?
            AND parent = ?
            AND bucket = ?
    ");
    $sth->bind_param(1, $_[0]);
    $sth->bind_param(2, $_[1]);
    $sth->bind_param(3, 'mfsermons.myflock2.com');
    $sth->execute;

    $result = '';
    while(my($id, $org_id, $name) = $sth->fetchrow_array())
    {
        $result .= "<option value='$id'>$name</option>";  #377
        $result .= directory_tree($org_id, $id);          #378
    }

    return $result;
}

$directory_tree = '<select name="folder">';
$directory_tree .= directory_tree($churchid, 0);
$directory_tree .= '</select>';

Why is it that when I print $result after line 377 that it is equal to the expected value, but when I print it on line 378, nothing appears? Shouldn’t the .= operator just run the function again, and then append to the value?

My best guess is that there are some scope issues in Perl I don’t understand, particularly with regards to $result. However, for the life of me, I can’t figure out what’s wrong, and I have absolutely no idea where to look!

When I turn on error reporting, fatals and warnings, nothing is returned. What could possibly be going wrong that I’m missing?

  • 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-06-14T23:39:52+00:00Added an answer on June 14, 2026 at 11:39 pm

    use strict, avoid global variables. In other words: you are reusing the global $result, resetting its value in each call to the subroutine.

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

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
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 want use html5's new tag to play a wav file (currently only supported
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm trying to create an if statement in PHP that prevents a single post

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.