SPUG: Variable in subroutines to check number of args?

John Costello cos at indeterminate.net
Thu Jul 13 13:48:43 PDT 2006

On Wed, 12 Jul 2006, Yitzchak Scott-Thoennes wrote:

> On Wed, Jul 12, 2006 at 02:31:58PM -0700, John Costello wrote:
> > On Wed, 12 Jul 2006, Tim Maher wrote:
> > > 
> > > You can use the following to load a variable with what you want:
> > > 
> > >    my $argc = @_; # get #-of-elements from @_ (sub-argument) array
> > 
> > How painfully obvious.
> > 
> > May I distract all of you with the 'use bytes' pragma while I run away?
> The use bytes pragma is almost never a good thing to use; you're not,
> are you?

I was using 'use bytes' for a brief period.

I'm converting data from shift-jis to unicode as part of a conversion of
for short) to SAP.

I don't control the specifications for the upload into SAP, which may be 
why I have a shred of sanity left.

Did I mention that UUPDA is a Japanese-language application, and that I'm 
dealing with romaji and kanji characters?  That's where things become 

The data files for upload to SAP are fixed-length records.  Why?  They 
just are.  Field #47 for kanji version of the company name needs to be, 
oh, let's say 100 characters.  I use 

	$record .= substr ( ( $k_company . (" " x 100) ), 0, 100);

to append the kanji company name to $record and pad the rightmost part of 
the field with blank spaces.  I could do this other ways with 'length' but 
I chose not to.

The catch is that 1 kanji character may occupy more than 1 byte.  When
output to a datafile, the record sometimes is 100 characters and sometimes
is longer--depending on how many bytes the kanji characters take.  This
should be okay if the data is read on a character-by-character basis, but
becomes an issue if the person doing the SAP upload switches from reading
things on a character-by-character basis to a byte-by-byte basis.  Throws 
everything off, in fact.

And switch is what they did.  So, I was looking at using 'use bytes' to 
output things based on byte length rather than character length.  
Fortunately (for me), someone else stepped in and told the SAP uploader 
coder to go back to character-by-character uploads.  Saved me the trouble 
of recoding parts of a longish program that were working fine.

I'm enjoying unicode and the challenge, but forgetting very obvious things 
like '$args = @_;' and the difference between the 'decaf' coffee tub and 
the 'regular like nature intended' coffee tub.

"Unicode is fun--you just have to define fun correctly."--Programming Perl

More information about the spug-list mailing list