62 users online (1 members and 61 guests)  


  Results 1 to 3 of 3

Related

  1. Split categories in half.    Forum: CGI Perl Forum
    Replies: 4
  2. [split] PHP upload script.    Forum: PHP Forum
    Replies: 3
  1. #1
    sharshav's Avatar
    New User

    Status
    Offline
    Join Date
    Aug 2007
    Posts
    1

    How to split a pipe separated string in CGI/Perl.

    Hi all,
    I am hitting some URL from my perl page, and getting some Values as response which are pipe separated.
    Here I have two queries,
    1) how to read that response into a local variable.
    2) How to split that local variable.

  2. #2
    xmassey's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Apr 2007
    Posts
    100

    Re: How to split a pipe separated string in CGI/Perl.

    Hello, not totally sure what you mean... But if you have a string like this...
    my $string = "One|Two|Three|Four|Five";
    Each element is devided using | character...
    We can split the string like this...
    my @string_split = split(/\|/, $string);
    now you can either use a foreach loop to do something to each element of the array or if you know which one you want...
    i.e.
    my $one_i_want = @string[2]
    ### $one_i_want would then have the value Three stored to it.
    About reading the response, not totally sure what you mean. Reading from a file? Or sending the data to the script directly?
    Chris

  3. #3
    xmassey's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Apr 2007
    Posts
    100

    Re: How to split a pipe separated string in CGI/Perl.

    I made a mistake...
    my $one_i_want = @string[2]
    should have been...
    my $one_i_want = @string_split[2]