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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:14:02+00:00 2026-05-15T02:14:02+00:00

I hava a perl subroutine where i would like to pass parameters as a

  • 0

I hava a perl subroutine where i would like to pass parameters as a hash
(the aim is to include a css depending on the parameter ‘iconsize’).

I am using the call:

get_function_bar_begin('iconsize' => '32');

for the subroutine get_function_bar_begin:

use strict;
...
sub get_function_bar_begin
{
    my $self = shift;
    my %template_params = %{ shift || {} };

    return $self->render_template('global/bars   /tmpl_incl_function_bar_begin.html',%template_params);
}

Why does this yield the error message:

Error executing run mode ‘start’: undef error – Can’t use string (“iconsize”) as a HASH ref while “strict refs” in use at CheckBar.pm at line 334

Am i doing something wrong here?
Is there an other way to submit my data (‘iconsize’) as a hash?

(i am still new to Perl)

EDIT: Solution which worked for me. I didn’t change the call, but my function:

sub get_function_bar_begin
{
    my $self = shift;
    my $paramref = shift;
    my %params = (ref($paramref) eq 'HASH') ? %$paramref : ();
    my $iconsize = $params{'iconsize'} || '';

    return $self->render_template('global/bars/tmpl_incl_function_bar_begin.html',
        {
            'iconsize'  => $iconsize,
        }
    );
}
  • 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-15T02:14:03+00:00Added an answer on May 15, 2026 at 2:14 am

    You are using the hash-dereferencing operator ( %{ } ) on the first argument of your parameter list. But that argument is not a hash reference, it’s just the string 'iconsize'. You can do what you want by one of two ways:

    Pass an anonymous hash reference:

    get_function_bar_begin( { 'iconsize' => '32' } );
    

    Or continue to pass a normal list, as you are right now, and change your function accordingly:

    sub get_function_bar_begin {
        my $self = shift;
        my %template_params = @_;
    }
    

    Notice in this version that we simply assign the argument list directly to the hash (after extracting $self). This works because a list of name => value pairs is just syntactic sugar for a normal list.

    I prefer the second method, since there’s no particularly good reason to construct an anonymous hashref and then dereference it right away.

    There’s also some good information on how this works in this post: Object-Oriented Perl constructor syntax.

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

Sidebar

Related Questions

I hava a function that looks something like this: require(config.php); function displayGta() { (...
I hava a java application that uses Buffers to pass object around between threads.
I hava a java program, a section of it is compute intensive, like this
I hava a .app application and I want to include it inside my project
I hava a url like mysite.net/home/index/page/XX while XX is any number. I need to
I hava a remote validator setup like so remote: { type: POST, url: /some/url,
I hava a listview like the following. The text in the TextView comes from
I hava a PHP script which generates a PDF file (i'm using fpdf from
I hava a project which will look like similar to Paint program. Here, I'm
I hava a web page with a link like something like <a href=myPage/MyServlet&param=12>... and

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.