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 3605642
In Process

The Archive Base Latest Questions

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

sub getHeading { my $var = $_[0]; my $match; if ($match = ($var =~

  • 0
sub getHeading
{
    my $var = $_[0];
    my $match;
     if ($match = ($var =~ m/$fivetonine/))
     {
        return "=";
     }
     if ($match = ($var =~ m/$tentofourteen/))
     {
        return "==";
     }
     if ($match = ($var =~ m/$fifteentonineteen/)){
        return "===";
     }
     return "===";
}
my $ref_to_getHeading = \getHeading;

and I am calling it via:

$html =~ s/(.*)<font size="([^"]+)">(.+)<\/font>(.*)/$ref_to_getHeading($2)$1$3$4$ref_to_getHeading($2)/m;

I am wanting to pass a string in to this function, I want to check if it is one of 3 different matches and return the appropriate number of = signs, I am doing this wrong but I can’t figure out how to make it take parameters? I get a run time error saying $var is initialised? I tried using @_ but I don’t really understand what the difference is.

Any help much appreciated, I have never written perl before and this is my first real program.

  • 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:08:58+00:00Added an answer on May 18, 2026 at 9:08 pm

    Double mistake there.

    First, you aren’t taking a reference to a function – You need to add the ampersand.

    But even if you do that, it won’t work. You are missing the /e flag in your substitution: You can’t dereference a coderef within a string like you’d normally do with (scalar|hash|array)ref:

    my $example = sub { return "hello" };
    say "$example->()"; #Will stringify the coderef.
    

    You either need the /e flag,

    $html =~ s/etc/$ref_to_getHeading->($2) . "$1$3$4" . $ref_to_getHeading->($2)/em;
    

    Or a little trick:

    $html =~ s/etc/@{[$ref_to_getHeading->($2)]}$1$3$4@{[$ref_to_getHeading->($2)]}/m;
    

    EDIT: Gosh, am I a slow typist..
    Anyhow, with either way, you should be able to call the sub directly, so no need for the coderef.

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

Sidebar

Related Questions

A python script need to spawn multiple sub-processes via fork(). All of those child
sub routine1 { return wantarray ? () : undef; } sub routine2 { return;
Given this: Public Sub timReminder_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) If DateTime.Now()
How to move a sub directory from one directory to another, given that both
I have classX: Sub New(ByVal item_line_no As String, ByVal item_text As String) ' check
i have a sub with this signature Public Sub Save(ByVal obj As IPta) now
Many beginning programmers write code like this: sub copy_file ($$) { my $from =
How do I copy a directory including sub directories excluding files or directories that
Let's say that I create a Sub (not a function) whose mission in life
I have a main form and as sub form. I need the main Form

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.