<?xml version="1.0" encoding="windows-1252"?>
<node id="369294" title="Re: chopping lots of characters" created="2004-06-24 07:45:21" updated="2005-08-10 21:45:05">
<type id="11">
note</type>
<author id="169744">
Abigail-II</author>
<data>
<field name="doctext">
As you said, substr is the way to go. &lt;tt&gt;chop&lt;/tt&gt; chops off one character, and not more than one. So, if you want to chop off 4 characters using &lt;tt&gt;chop&lt;/tt&gt;, you need to &lt;tt&gt;chop&lt;/tt&gt; 4 times. Either by duplicating the line, or by using a loop. You might want to bail out if the string is empty:
&lt;code&gt;
my $i = 4;
chop $string while $i -- &amp;&amp; length $string;
&lt;/code&gt;
Or
&lt;code&gt;
my $i = 4;
1 while $i -- &amp;&amp; defined chop $string;
&lt;/code&gt;
although the latter might want to chop an empty string (but only once).
&lt;p&gt;
Abigail</field>
<field name="root_node">
369291</field>
<field name="parent_node">
369291</field>
</data>
</node>
