Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Perl newbie please help

Reply
Thread Tools

Perl newbie please help

 
 
Jordy Keighan
Guest
Posts: n/a
 
      07-08-2004
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:OM:arser->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&MEM BER_NAME="
.. $ENV{DACS_ACS_JURISDICTION} . ":" . $user_array[0].
"&JURISDICTION=CUBEWERX&DACS_VERSION=1.2&FORMAT=xm l"); # STATEMENT
HANGS !!!!

Please help.

Jordy

...
 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      07-08-2004
On Thu, 8 Jul 2004, Jordy Keighan wrote:

> 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:OM:arser->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&MEM BER_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=xm l"); # 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
 
Reply With Quote
 
 
 
 
John W. Krahn
Guest
Posts: n/a
 
      07-09-2004
Paul Lalli wrote:
>
> On Thu, 8 Jul 2004, Jordy Keighan wrote:
> >
> > @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
--
use Perl;
program
fulfillment
 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      07-09-2004
On Fri, 9 Jul 2004, John W. Krahn wrote:

> Paul Lalli wrote:
> >
> > On Thu, 8 Jul 2004, Jordy Keighan wrote:
> > >
> > > @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
 
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
Please help me pass an array from VBA to Perl and populate it. Newbie at wits' end! david.f.jenkins@usa.net Perl Misc 10 10-06-2006 07:18 PM
Please help Perl Newbie understand this statement jm-1@remotekontrol.com Perl Misc 10 06-27-2006 09:36 AM
HELP! HELP! PLEASE, PLEASE, PLEASE tpg comcntr Computer Support 11 02-15-2004 06:22 PM
please help... ...me learn C++ please please please :) KK C++ 2 10-14-2003 02:08 PM
Perl Help - Windows Perl script accessing a Unix perl Script dpackwood Perl 3 09-30-2003 02:56 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57