P
P
Petr Beklemishev2014-11-26 19:14:14
Perl
Petr Beklemishev, 2014-11-26 19:14:14

Problem with split (perl)?

I'm trying to use split to split a string ($myline) of the form:
+1,-2,+5into substrings separated by commas, but everything fails with an error:
eef252d789d84c5595c6fc6c7039a376.png
Code:

if ($myline ne '.') {
      @tmp_users = split(/\,/, $myline);
      foreach $tmp_user (@tmp_users) {
        switch (split($tmp_user, 0, 1)) {
          case '+'  {
            print '+++', $tmp_user,'\n';
          }
          case '-'  {
            print '-', $tmp_user,'\n';
          }
          else {
            if (isdigit $tmp_user) {
              print '_', $tmp_user,'\n';
              @users = (@users, $username[$tmp_user]);
            } else {
              #  print 'else else cond_';
            }
          }
        }
      }
    } else {
      #изменений в составе команды проекта нет
      print 'ok';
    }

If the line is of the form .or 1,9then everything works fine.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir, 2014-11-26
@Vasia529

replace
switch (split($tmp_user, 0, 1)) {
with
switch (substr($tmp_user, 0, 1)) {

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question