CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Splitting hash value

 



mmcw
User

Oct 23, 2003, 9:08 AM

Post #1 of 3 (223 views)
Splitting hash value Can't Post

            I am using the folloing script:


Code
 #!/usr/bin/perl -w 

%credit_form_fields_extra = (
"Cash in advance" => "",
"Send a check" => "",
"Authorize for once" => "Bank Account|test",
"Cash on delivery" => "",
"By credit card" => "Card Type|Card Holder Name|Card Number|Exp Month|Exp Year"
);

print "Content-Type: text/html\015\012\015\012";

foreach (keys %credit_form_fields_extra) {
if ($_ eq "Authorize for once") {
my @test = split("|",$credit_form_fields_extra{$_});

foreach my $test (@test) {
print "a: $test<br>";
}
}
}

1;


I want to split the $credit_form_fields_extra{'Authorize for once'} to an array @test.
The loop:

foreach my $test (@test) {
print "a: $test<br>";
}

has to return: a: Bank Account
a: test

But it returns:

a: B
a: a
a: n
a: k
a:
a: A
a: c
a: c
a: o
a: u
a: n
a: t
a: |
a: t
a: e
a: s
a: t

What am I doing wrong?


KevinR
Veteran


Oct 23, 2003, 11:29 AM

Post #2 of 3 (221 views)
Re: [mmcw] Splitting hash value [In reply to] Can't Post

I think it should be like this:


Code
my @test = split(/\|/,$credit_form_fields_extra{$_});

-------------------------------------------------


(This post was edited by KevinR on Oct 23, 2003, 11:30 AM)


mmcw
User

Oct 23, 2003, 11:23 PM

Post #3 of 3 (216 views)
Re: [KevinR] Splitting hash value [In reply to] Can't Post

thanks a lot!

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives