Perl newbie please help

J

Jordy Keighan

I am trying to compose a URI with some values that I get
from parsing a XML string.

If I print $user_array[0] ===> value = 'bob'
but if I us it in URI->new( ... $user_array[0] ... ) the program
hangs.

If I manualy put 'bob' in $user_array[0]
all is good and the URI->new( ... $user_array[0] ... ) statement
works.

Wy can't I use the string I got from my XML parsing ???

Here is my code:

my $user_string = "";
my $parser = XML::DOM::parser->new();
my $doc = $parser->parse($xml);
foreach my $key ($doc->getElementsByTagName('credentials')){
$user_string = $user_string . $key->getAttribute('name') .
" ";
}
@user_array = split(" ", $user_string);

print $user_array[0]; # VALUE OK prints bob!!!!


my $uri = URI->new("https://" . $ENV{HTTP_HOST} .
/cgi-bin/dacs/dacs_group.cgi?OPERATION=LIST_GROUP_MEMBERSHIP&MEMBER_NAME="
.. $ENV{DACS_ACS_JURISDICTION} . ":" . $user_array[0].
"&JURISDICTION=CUBEWERX&DACS_VERSION=1.2&FORMAT=xml"); # STATEMENT
HANGS !!!!

Please help.

Jordy

...
 
P

Paul Lalli

Subject: Perl newbie please help

This is a very unhelpful subject. In the future, you should try to use a
subject that actually describes your problem. In this case, perhaps
"URI->new() hanging" or something similar.
I am trying to compose a URI with some values that I get
from parsing a XML string.

If I print $user_array[0] ===> value = 'bob'
but if I us it in URI->new( ... $user_array[0] ... ) the program
hangs.

If I manualy put 'bob' in $user_array[0]
all is good and the URI->new( ... $user_array[0] ... ) statement
works.

Wy can't I use the string I got from my XML parsing ???

Here is my code:

my $user_string = "";
my $parser = XML::DOM::parser->new();
my $doc = $parser->parse($xml);
foreach my $key ($doc->getElementsByTagName('credentials')){
$user_string = $user_string . $key->getAttribute('name') .
" ";
}
@user_array = split(" ", $user_string);

Why are you doing this? Why are you composing one large string, manually
separating each field with spaces, and then using split to get an array
back out? Unless you're using $user_string later in unshown code (and if
you are, feel free to ignore me here), conider changing this to:
my @user_array;
foreach my $key ($doc->getElementsByTagName('credentials')){
push @user_array, $key->getAttribute('name');
}

print $user_array[0]; # VALUE OK prints bob!!!!

out of curiousity, does it really print *just* bob? Or does the value
perhaps have extra whitespace attached to either end? What does this
print?
print "'$user_array[0]'\n";
my $uri = URI->new("https://" . $ENV{HTTP_HOST} .
/cgi-bin/dacs/dacs_group.cgi?OPERATION=LIST_GROUP_MEMBERSHIP&MEMBER_NAME="

There's a problem here. You're missing a double-quote. That should be a
syntax error. This leads me to believe you have not shown us your actual
code, but have instead re-typed it into this post. That's a Bad Thing.
Please make sure you copy and paste the actual text, so we can verify
we're looking at exactly what you're lookin gat.

. $ENV{DACS_ACS_JURISDICTION} . ":" . $user_array[0].
"&JURISDICTION=CUBEWERX&DACS_VERSION=1.2&FORMAT=xml"); # STATEMENT
HANGS !!!!

What exactly do you mean by "hangs"? If you put a print statement
immediately after this line, like:
print "debuggin!\n";

does this line not get printed?


Paul Lalli
 
J

John W. Krahn

Paul said:
@user_array = split(" ", $user_string);

Why are you doing this? Why are you composing one large string, manually
separating each field with spaces, and then using split to get an array
back out? Unless you're using $user_string later in unshown code (and if
you are, feel free to ignore me here), conider changing this to:
my @user_array;
foreach my $key ($doc->getElementsByTagName('credentials')){
push @user_array, $key->getAttribute('name');
}
print $user_array[0]; # VALUE OK prints bob!!!!

out of curiousity, does it really print *just* bob? Or does the value
perhaps have extra whitespace attached to either end?

It can't have any whitespace as the previous line removes all
whitespace.


John
 
P

Paul Lalli

Paul said:
@user_array = split(" ", $user_string);
print $user_array[0]; # VALUE OK prints bob!!!!

out of curiousity, does it really print *just* bob? Or does the value
perhaps have extra whitespace attached to either end?

It can't have any whitespace as the previous line removes all
whitespace.

Whoops. I was confusing
split ' ';
with
split / /;


My mistake. Thanks for catching that.

Paul Lalli
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top