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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:00:22+00:00 2026-05-14T03:00:22+00:00

Perl allows … $a = fee; $result = 1 + f($a) ; # invokes

  • 0

Perl allows …

$a = "fee";
$result = 1 + f($a) ; # invokes f with the argument $a

but disallows, or rather doesn’t do what I want …

s/((fee)|(fie)|(foe)|(foo))/f($1)/ ; # does not invoke f with the argument $1

The desired-end-result is a way to effect a substitution geared off what the regex matched.

Do I have to write

sub lala {
  my $haha = shift;
  return $haha . $haha;
}
my $a = "the giant says foe" ;
$a =~ m/((fee)|(fie)|(foe)|(foo))/;
my $result = lala($1);
$a =~ s/$1/$result/;
print "$a\n";
  • 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-14T03:00:22+00:00Added an answer on May 14, 2026 at 3:00 am

    See perldoc perlop. You need to specify the e modifier so that the replacement part is evaluated.

    #!/usr/bin/perl
    
    use strict; use warnings;
    
    my $x = "the giant says foe" ;
    $x =~ s/(f(?:ee|ie|o[eo]))/lala($1)/e;
    
    print "$x\n";
    
    sub lala {
        my ($haha) = @_;
        return "$haha$haha";
    }
    

    Output:

    C:\Temp> r
    the giant says foefoe

    Incidentally, avoid using $a and $b outside of sort blocks as they are special package scoped variables special-cased for strict.

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

Sidebar

Related Questions

Is there a popular Perl module that works like Data::Dumper but allows user to
Is there a package in Perl that allows you to compute the height of
I need to create Perl code which allows counting paragraphs in text files. I
In Perl there is a very handy module, Term::VT102, which allows you to create
Perl has OOP features, but they are somewhat rarely used. How do you create
I've written a wrapper program for mailx using perl that allows me to easily
I'm looking for a statistics package for Perl (CPAN is fine) that allows me
Perl's Data::Rmap allows you to recursively evaluate a BLOCK over a list of data
I'd like to connect to a Hadoop-based Hive datastore using Perl. Hive allows connection
I'm using REST::Client perl module to test my REST server. I want to print

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.