View Full Version : splitting array returned from MySQL query
Hi,
I have a MySQL query which returns the array - Accommodation 00000000001
I need to split this into two values , Accommodation and number. I feel rusty coz this doesn't do it for me:
my ($Value, $pk) = split /\ / , @fields, 2;
pointers or (gentle), wake up calls welcome. ;)
EDIT:
finally got it: @fields[0] and @fields[1]
bazz
FishMonger
11-29-2007, 12:18 AM
Hi,
I have a MySQL query which returns the array - Accommodation 00000000001
I need to split this into two values , Accommodation and number. I feel rusty coz this doesn't do it for me:
my ($Value, $pk) = split /\ / , @fields, 2;
pointers or (gentle), wake up calls welcome. ;)
EDIT:
finally got it: @fields[0] and @fields[1]
bazz
You mean:
$fields[0] and $fields[1]
well yeah I do but, it works with @fields[0] and @fields[1] too. I don't know why but I have changed it to $
Thanks
bazz
FishMonger
11-29-2007, 12:51 AM
well yeah I do but, it works with @fields[0] and @fields[1] too. I don't know why but I have changed it to $
Thanks
bazz
I take it that you don't have warnings enabled!
#!perl
use warnings;
use strict;
my @fields = qw(Accommodation 00000000001);
print "@fields[0]\n@fields[1]\n";
C:\testing>bazz.pl
Scalar value @fields[0] better written as $fields[0] at C:\testing\bazz.pl line 7.
Scalar value @fields[1] better written as $fields[1] at C:\testing\bazz.pl line 7.
Accommodation
00000000001
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.