# missing 0s

#### Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

•  Subject
• Author
• Posted on
I have line in a file
001-02-0003

I do
Now I print them I get 1,2,3 instead of 001,02,0003.

## Re: missing 0s

Min Wang wrote:
> I have line in a file
> 001-02-0003
>
> I do
> (\$a,\$b,\$c) = split('-',\$_) after read.
> Now I print them I get 1,2,3 instead of 001,02,0003.

\$_ = '001-02-0003';
my (\$x,\$y,\$z) = split /-/;
print "\$x,\$y,\$z\n";

Outputs:
001,02,0003

--
Email: http://www.gunnar.cc/cgi-bin/contact.pl

## Re: missing 0s

Gunnar,

Thank you very much.

Furthermore,

I tried

\$x = substr(\$b, 0, 1);
\$y = substr(\$b, 1);

I expect to have \$x=0 and \$y=2.
In stead, I got \$x = 2 and \$y is null.

Thanks.

> Min Wang wrote:
> > I have line in a file
> > 001-02-0003
> >
> > I do
> > (\$a,\$b,\$c) = split('-',\$_) after read.
> > Now I print them I get 1,2,3 instead of 001,02,0003.
>
>      \$_ = '001-02-0003';
>      my (\$x,\$y,\$z) = split /-/;
>      print "\$x,\$y,\$z\n";
>
> Outputs:
> 001,02,0003

## Re: missing 0s

> Gunnar,
>
> Thank you very much.
>
> Furthermore,
>
> I tried
>
> \$x = substr(\$b, 0, 1);
> \$y = substr(\$b, 1);
>
> I expect to have \$x=0 and \$y=2.
> In stead, I got \$x = 2 and \$y is null.

No you don't:

\$_ = '001-02-0003';
(\$a,\$b,\$c) = split('-',\$_);
\$x = substr(\$b, 0, 1);
\$y = substr(\$b, 1);
print "*\$x* *\$y*\n";

Stop posting snippets of code and instead post a small self contained
script that demonstrates the problem. It'll only be a few lines long...

[snip a full quote, from which I retrieved the \$_ = and split bits]

--
Sam Holden

## Re: missing 0s

Min Wang wrote:
>> Min Wang wrote:
>>> I have line in a file
>>> 001-02-0003
>>>
>>> I do
>>> (\$a,\$b,\$c) = split('-',\$_) after read.
>>> Now I print them I get 1,2,3 instead of 001,02,0003.
>>
>>     \$_ = '001-02-0003';
>>     my (\$x,\$y,\$z) = split /-/;
>>     print "\$x,\$y,\$z\n";
>>
>> Outputs:
>> 001,02,0003
>
> Thank you very much.
>
> Furthermore,
>
> I tried
>
> \$x = substr(\$b, 0, 1);
> \$y = substr(\$b, 1);
>
> I expect to have \$x=0 and \$y=2.
> In stead, I got \$x = 2 and \$y is null.

my \$first = substr \$y, 0, 1;
my \$second = substr \$y, 1;
print "First: \$first, second: \$second\n";

Outputs:
First: 0, second: 2

Funny computer you have. :)