Mar 14, 2012 10:51 am
TorquedI have a code which goes like this
#!/usr/bin/perl -w
use strict;
my @column;
while (<DATA>) {
push @column, (split)[0];
print join (' ', @column);
}
__DATA__
1 a b c
2 d e f
3 g h i
But when running this i get the output as : 11 21 2 3
Whereas i am trying to get the output as : 1 2 3
could you please suggest what i am doing wrong here?
Regards.../om
Mar 14, 2012 11:19 am
Timothy adigun--e89a8ffbaea326e05b04bb322578
Content-Type: text/plain; charset=ISO-8859-1
Hi Torqued,
On Wed, Mar 14, 2012 at 11:51 AM, Torqued <torque.india@gmail.com> wrote:
> I have a code which goes like this
>
> #!/usr/bin/perl -w
> use strict;
>
> my @column;
>
my $k;>
> #!/usr/bin/perl -w
> use strict;
>
> my @column;
>
> while (<DATA>) {
> push @column, (split)[0];
> #print join (' ', @column);
>
$k=join (' ', @column);> push @column, (split)[0];
> #print join (' ', @column);
>
> }
>
print $k;>
> ***OUTPUT**
>
1 2 3>
> __DATA__
> 1 a b c
> 2 d e f
> 3 g h i
>
> But when running this i get the output as : 11 21 2 3
> Whereas i am trying to get the output as : 1 2 3
>
> could you please suggest what i am doing wrong here?
>
> Regards.../om
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
>
>
>
> 1 a b c
> 2 d e f
> 3 g h i
>
> But when running this i get the output as : 11 21 2 3
> Whereas i am trying to get the output as : 1 2 3
>
> could you please suggest what i am doing wrong here?
>
> Regards.../om
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
>
>
>
Tim
--e89a8ffbaea326e05b04bb322578--
--e89a8ffbaea326e05b04bb322578--
Mar 14, 2012 11:24 am
Timothy adigun--047d7b33d85eb9740d04bb32370c
Content-Type: text/plain; charset=ISO-8859-1
OR use:
#!/usr/bin/perl -w
use strict;
my @column;
while (<DATA>) {
push @column, (split)[0];
}
print join " ",@column;
__DATA__
1 a b c
2 d e f
3 g h i
On Wed, Mar 14, 2012 at 12:19 PM, timothy adigun <2teezperl@gmail.com>wrote:
> Hi Torqued,
>
> On Wed, Mar 14, 2012 at 11:51 AM, Torqued <torque.india@gmail.com> wrote:
>
>
>
>
>
>
>
> --
> Tim
>
>
>
> On Wed, Mar 14, 2012 at 11:51 AM, Torqued <torque.india@gmail.com> wrote:
>
>> I have a code which goes like this
>>
>> #!/usr/bin/perl -w
>> use strict;
>>
>> my @column;
>>
> my $k;>>
>> #!/usr/bin/perl -w
>> use strict;
>>
>> my @column;
>>
>
>> while (<DATA>) {
>> push @column, (split)[0];
>> #print join (' ', @column);
>>
> $k=join (' ', @column);>> push @column, (split)[0];
>> #print join (' ', @column);
>>
>
>> }
>>
> print $k;>>
>
>> ***OUTPUT**
>>
> 1 2 3>>
>
>
>> __DATA__
>> 1 a b c
>> 2 d e f
>> 3 g h i
>>
>> But when running this i get the output as : 11 21 2 3
>> Whereas i am trying to get the output as : 1 2 3
>>
>> could you please suggest what i am doing wrong here?
>>
>> Regards.../om
>>
>> --
>> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
>> For additional commands, e-mail: beginners-help@perl.org
>> http://learn.perl.org/
>>
>>
>>
>>> 1 a b c
>> 2 d e f
>> 3 g h i
>>
>> But when running this i get the output as : 11 21 2 3
>> Whereas i am trying to get the output as : 1 2 3
>>
>> could you please suggest what i am doing wrong here?
>>
>> Regards.../om
>>
>> --
>> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
>> For additional commands, e-mail: beginners-help@perl.org
>> http://learn.perl.org/
>>
>>
>>
>
> --
> Tim
>
>
Tim
--047d7b33d85eb9740d04bb32370c--
--047d7b33d85eb9740d04bb32370c--
Mar 14, 2012 11:37 am
Torqued--Apple-Mail-9AF0244B-B415-4FA5-B7B4-224F3A0DE316
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
charset=us-ascii
It worked like charm, but a quick question, why the print is misbehaving und=
er the loop, but once out how it print right result.
Regards.../om
On 14-Mar-2012, at 16:54, timothy adigun <2teezperl@gmail.com> wrote:
> OR use:
> #!/usr/bin/perl -w
> use strict;
>=20
> my @column;
> while (<DATA>) {
> push @column, (split)[0]; =20
> }
> print join " ",@column;
>=20
> __DATA__
> 1 a b c
> 2 d e f
> 3 g h i
>=20
> On Wed, Mar 14, 2012 at 12:19 PM, timothy adigun <2teezperl@gmail.com> wro=
te:> #!/usr/bin/perl -w
> use strict;
>=20
> my @column;
> while (<DATA>) {
> push @column, (split)[0]; =20
> }
> print join " ",@column;
>=20
> __DATA__
> 1 a b c
> 2 d e f
> 3 g h i
>=20
> On Wed, Mar 14, 2012 at 12:19 PM, timothy adigun <2teezperl@gmail.com> wro=
> Hi Torqued,
>=20
> On Wed, Mar 14, 2012 at 11:51 AM, Torqued <torque.india@gmail.com> wrote:
> I have a code which goes like this
>=20
> #!/usr/bin/perl -w
> use strict;
>=20
> my @column;
> my $k;=20
> while (<DATA>) {
> push @column, (split)[0];
> #print join (' ', @column);
> $k=3Djoin (' ', @column);
> }
> print $k;=20
> ***OUTPUT**
> 1 2 3
> =20
> __DATA__
> 1 a b c
> 2 d e f
> 3 g h i
>=20
> But when running this i get the output as : 11 21 2 3
> Whereas i am trying to get the output as : 1 2 3
>=20
> could you please suggest what i am doing wrong here?
>=20
> Regards.../om
>=20
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
>=20
>=20
>=20
>=20
>=20
> --=20
> Tim
>=20
>=20
>=20
>=20
> --=20
> Tim
>=20
>=20
> On Wed, Mar 14, 2012 at 11:51 AM, Torqued <torque.india@gmail.com> wrote:
> I have a code which goes like this
>=20
> #!/usr/bin/perl -w
> use strict;
>=20
> my @column;
> my $k;=20
> while (<DATA>) {
> push @column, (split)[0];
> #print join (' ', @column);
> $k=3Djoin (' ', @column);
> }
> print $k;=20
> ***OUTPUT**
> 1 2 3
> =20
> __DATA__
> 1 a b c
> 2 d e f
> 3 g h i
>=20
> But when running this i get the output as : 11 21 2 3
> Whereas i am trying to get the output as : 1 2 3
>=20
> could you please suggest what i am doing wrong here?
>=20
> Regards.../om
>=20
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
>=20
>=20
>=20
>=20
>=20
> --=20
> Tim
>=20
>=20
>=20
>=20
> --=20
> Tim
>=20
--Apple-Mail-9AF0244B-B415-4FA5-B7B4-224F3A0DE316--
Previous Thread: How to put the match in an array
Next Thread: Install modules from CPAN