Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Evaluate variable while using

by hippo (Bishop)
on Oct 21, 2022 at 11:34 UTC ( [id://11147562]=note: print w/replies, xml ) Need Help??


in reply to Evaluate variable while using

I'm not sure how to achieve this.

The How depends mostly on the Why - and you have not explained that. This is probably an XY Problem.

One solution is a closure.

#!/usr/bin/env perl use strict; use warnings; my $x; sub greeting { my $str = 'Hello ' . $x; print $str . "\n"; } $x = 'Kevin'; greeting (); $x = 'chickenman'; greeting ();

🦛

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11147562]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-03-28 22:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found