Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > missing 0s

Reply
Thread Tools

missing 0s

 
 
Min Wang
Guest
Posts: n/a
 
      09-01-2004
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.

Please help and thanks.
 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      09-01-2004
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

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
 
 
 
Anno Siegel
Guest
Posts: n/a
 
      09-02-2004
Min Wang <(E-Mail Removed)> wrote in comp.lang.perl.misc:
> 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.


How do you print them? Explaining in English what you (think you) did
is insufficient. Show your code!

If you print them in a normal print-statement immediately after the
split, the zeroes will show up. Gunnar has demonstrated that in
his reply. So what else are you doing? Are you using printf for
printing? With what format? Is there intervening code between the
split() and print()?

Anno
 
Reply With Quote
 
Min Wang
Guest
Posts: n/a
 
      09-02-2004
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.

Gunnar Hjalmarsson <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> 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

 
Reply With Quote
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      09-02-2004
Min Wang wrote:
> Gunnar Hjalmarsson 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.

How about following Anno's advice and post the exact code that
produces the results you say it does?

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
Sam Holden
Guest
Posts: n/a
 
      09-02-2004
On 2 Sep 2004 04:41:01 -0700, Min Wang <(E-Mail Removed)> wrote:
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Crystal Reports - Visual Basic UFL that implements this function is missing (or U2lcom.dll is missing) Les Caudle ASP .Net 3 09-03-2007 02:27 AM
Re: missing feature classes and missing fields Gary Herron Python 2 07-04-2006 10:29 PM
missing wzcdlg.dll =?Utf-8?B?RGFuZGVl?= Wireless Networking 4 11-20-2004 02:14 PM
Missing Wireless Link applet =?Utf-8?B?Q2hyaXNzaWU=?= Wireless Networking 8 10-07-2004 07:24 PM
Missing Websites and no mail =?Utf-8?B?U2hpZnR3b3JrZXI0Mw==?= Wireless Networking 0 09-11-2004 12:31 PM



Advertisments