Perl newbie please help

Discussion in 'Perl Misc' started by Jordy Keighan, Jul 8, 2004.

  1. 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

    ...
     
    Jordy Keighan, Jul 8, 2004
    #1
    1. Advertising

  2. Jordy Keighan

    Paul Lalli Guest

    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::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
     
    Paul Lalli, Jul 8, 2004
    #2
    1. Advertising

  3. 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
     
    John W. Krahn, Jul 9, 2004
    #3
  4. Jordy Keighan

    Paul Lalli Guest

    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
     
    Paul Lalli, Jul 9, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    4
    Views:
    564
    Chris Uppal
    May 5, 2005
  2. KK
    Replies:
    2
    Views:
    705
    Big Brian
    Oct 14, 2003
  3. MuZZy
    Replies:
    7
    Views:
    1,821
    Mike Hewson
    Jan 7, 2005
  4. Replies:
    10
    Views:
    194
    Dr.Ruud
    Jun 27, 2006
  5. Replies:
    10
    Views:
    503
    Tad McClellan
    Oct 6, 2006
Loading...

Share This Page