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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:32:42+00:00 2026-06-06T07:32:42+00:00

I’m building a stress-system in Perl for correcting students programming assignments. I built a

  • 0

I’m building a stress-system in Perl for correcting students programming assignments. I built a function check(<boolean>,<congrats-message>,<blame-message>) that is supposed to help me along the way.

When I invoke it as

check(get_option('content-type') eq "text/html","good type", "bad type");

everything is fine. But if I dare to do

check(get_option('content-type') =~ m:text/html:i, "good type", "bad type");

it breaks when the regexp doesn’t find a match. Actually it is then equivalent to a check("good type", "bad type"). I use only $_[0], $_[1] etc. in check() function, and it’s not like I had ‘undef’ as first argument: I can really catch the bug with die unless $#_ == 2.

What’s happening ? I worked it around with

check((get_option('content-type') =~ m:text/html:i && 1), "good type", "bad type");

but I’d love to understand the what and why of this odd situation.

—

sub check {
  if ($_[0]) {
    $okay++;
    print STDERR "^_^ $_[1] ($okay)\n";
  } else {
    print STDERR ">_< $_[2]\n";
  }
  return $_[0];
}
  • 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-06T07:32:44+00:00Added an answer on June 6, 2026 at 7:32 am

    eq always returns true or false, but =~ (when in list context) returns “a list consisting of the subexpressions matched by the parentheses in the pattern,”.

    When you put a list inside another list (e.g. the list of matches inside the list of arguments to the subroutine), they get merged.

    If there are 0 matches, you get the 2 other arguments in the list.

    If there are 2 matches, you get those 2 matches then the 2 other arguments for a total of 4 arguments.

    Your code depends on there being exactly three arguments.

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

Sidebar

Related Questions

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
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.