From 221615b2aad2856145fad0bdfde4de2f985b004c Mon Sep 17 00:00:00 2001
From: Nick Clemens <nick@bywatersolutions.com>
Date: Thu, 19 Dec 2019 19:05:36 +0000
Subject: [PATCH] Bug 9156: (follow-up) Simpliy code

The MARC::Field as_string method can join multiple subfield using a delimiter, this simplifies the code here

Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
---
 cataloguing/additem.pl | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl
index 38fb34bc3c..babf6d3d4c 100755
--- a/cataloguing/additem.pl
+++ b/cataloguing/additem.pl
@@ -156,18 +156,10 @@ sub generate_subfield_form {
         if (!$value && $subfieldlib->{kohafield} eq 'items.itemcallnumber' && $pref_itemcallnumber) {
             my $CNtag       = substr( $pref_itemcallnumber, 0, 3 ); # 3-digit tag number
             my $CNsubfields = substr( $pref_itemcallnumber, 3 ); # Any and all subfields
-            my @subfields = ( $CNsubfields =~ m/./g ); # Split into single-character elements
             my $temp2 = $temp->field($CNtag);
 
             if ($temp2) {
-                my @selectedsubfields;
-                foreach my $subfieldcode( @subfields ){
-                    push @selectedsubfields, $temp2->subfield( $subfieldcode );
-                }
-                $value = join( ' ', @selectedsubfields );
-
-                #remove any trailing space incase one subfield is used
-                $value =~ s/^\s+|\s+$//g;
+                $value = $temp2->as_string( $CNsubfields, ' ' );
             }
         }
 
-- 
2.11.0