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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:04:34+00:00 2026-05-27T19:04:34+00:00

I’m writting a small server with perl. There is some small problem. When the

  • 0

I’m writting a small server with perl. There is some small problem. When the client give me a sentence like this “op:xxx:xxx:xxx”, I’ll get op. then do things depending on what op is. It works will if the op is adduser and so on. (I use if $op eq “adduser”…)
But when I get a “getList:xxx:xxx” and I have get the $op = getList, it can’t pass it like “if $op eq “getList””. I know, it must be my mistake. But I just can’t find it.
thank you for everyone.

use warnings;
use strict;

package MyPackage;
use base qw(Net::Server);
our %data_base;
our %tag_base;
sub list {
    my %resault;
    foreach ( keys %tag_base) {
        print STDERR $_ . "1";
        my @tags = split /:/, $tag_base{$_};
        foreach ( @tags) {
            $resault{$_} ++;
        }
    }
    my @tags;
    foreach ( keys %resault) {
        push @tags, "$_,$resault{$_}";
    }
    $_ = join ";", @tags;
    print ;
    print STDERR ;
}

sub users {
    my $topic = shift;
    my @users;
    foreach ( keys %tag_base) {
        push @users, $_ if $tag_base{$_} =~ /$topic/;
    }
    $_ = join ";", @users;
    print ;
}

sub process_request {
    my $self = shift;
    my $person;
    my @info;
    while (<STDIN>) {
        my @gets = split /:/, $_;
        print STDERR "@gets\n";
        # $data_base{shift @person} = join ":", @person;
        my $op = shift @gets;
        $op =~ s/\s//;
        print STDERR $op . "\n";
        if (  $op eq "adduser") {
            my $user_name = shift @gets;
            if ( exists $data_base{$user_name}) {
                print "already_exist";
            } else {
                $data_base{$user_name} = join ":", @gets;
                print "addUserSu";
            }            
        } elsif ( $op eq "login") {
            my $login_name = shift @gets;
            my $login_pw   = shift @gets;
            if ( defined $data_base{$login_name}) {
                $person = $data_base{$login_name};
                @info   = split /:/, $person;
                $info[0] =~ s/\s+//;
                if ($login_pw eq $info[0]) {
                    print "$person";
                } else {
                    print "/$info[0]/";
                }
            } else {
                print "unexist_user";
            }
        } elsif ( $op eq "addTag") {
            my $tag_user = shift @gets;
            $tag_base{$tag_user} = join ":", @gets;
            print "addTagSu";
        } elsif ( $op eq "getList") {
            print STDERR "right";
            &list;
        } elsif ( $op eq "getUsers") {
            &users;
        }
    }
}

MyPackage->run(port => 13800);
  • 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-27T19:04:35+00:00Added an answer on May 27, 2026 at 7:04 pm

    I can see two (simple) reasons this might fail:

    $op =~ s/\s//;
    

    You only remove one whitespace: The first one. If your intention is to strip all whitespace, you’d want s/\s+//g.

    And second:

    Random capital letters in strings, variable names and commands is Evil. eq is case sensitive, so if $op is "getlist", then if ($op eq "getList") will be false. Unless capitalization is important to you, you could do if (lc($op) eq "getlist").

    Without sample input, expected output and actual output, this is however nothing more than guesswork.

    Also, as a debug statement, this is useless:

    print STDERR $op . "\n";
    

    That is easily confused and overlooked. For example, if $op is empty, it just produces a blank line in your error log. Use:

    print STDERR "OP is: '$op'\n";
    

    Now you will be able to identify the line where $op should appear, and you will be more easily see whitespace surrounding it.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I am currently running into a problem where an element is coming back from

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.