FAQ
I have a bunch of text files that follow the format
variable = value <crlf>

I am trying to read each file and insert it into SQL but before I can do
that I need to parse
the values into a hash.

One of the fields has the URL which can contain & and = characters, so after
the first split I seem to miss the rest.

I tried using the LIMIT feature of split which if I am reading it correctly
'limits the amount of times it will split'.

But I am not getting the desired results. See example

TEXT FILE HAS THIS
$method="GET";
$engname="SurfGopher";
$line="http://www.surfgopher.com/cgi-bin/submit.cgi";
$myquery="url=$url&email=$email&i_rank=yes";

When I run the script and print the output I get this
MYQUERY =
value = www.surfgopher.com/cgi-bin/submit.cgi
value = GET
value = SurfGopher

THIS IS THE LINE OF CODE USING SPLIT
if ($_ =~ /^\$myquery/) { (undef, $line{myquery}) = split(/=/, $_, 1) }

THIS IS THE LINE PRINTING THE OUTPUT IN QUESTION
print "MYQUERY = $line{myquery}\n";


I could just do a $line =~ s/\$myquery\=//;
and be done with it, but I want to know why and how to use the LIMIT
argument.

Thanks
zack

Search Discussions

  • Zachary Buckholz at May 13, 2002 at 11:48 pm
    Think I figured it out properly.

    if ($_ =~ /^\$myquery/) { quotemeta($_); (undef, $line{myquery}) =
    split(/=/, $_, 2); }

    This gives me MYQUERY = "url=$url&email=$email&i_rank=yes";

    If this is not the 'proper' way please let me know of a better way.

    Thanks
    zack


    "Zachary Buckholz" <[email protected]> wrote in message
    news:[email protected]...
    I have a bunch of text files that follow the format
    variable = value <crlf>

    I am trying to read each file and insert it into SQL but before I can do
    that I need to parse
    the values into a hash.

    One of the fields has the URL which can contain & and = characters, so after
    the first split I seem to miss the rest.

    I tried using the LIMIT feature of split which if I am reading it correctly
    'limits the amount of times it will split'.

    But I am not getting the desired results. See example

    TEXT FILE HAS THIS
    $method="GET";
    $engname="SurfGopher";
    $line="http://www.surfgopher.com/cgi-bin/submit.cgi";
    $myquery="url=$url&email=$email&i_rank=yes";

    When I run the script and print the output I get this
    MYQUERY =
    value = www.surfgopher.com/cgi-bin/submit.cgi
    value = GET
    value = SurfGopher

    THIS IS THE LINE OF CODE USING SPLIT
    if ($_ =~ /^\$myquery/) { (undef, $line{myquery}) = split(/=/, $_, 1) }

    THIS IS THE LINE PRINTING THE OUTPUT IN QUESTION
    print "MYQUERY = $line{myquery}\n";


    I could just do a $line =~ s/\$myquery\=//;
    and be done with it, but I want to know why and how to use the LIMIT
    argument.

    Thanks
    zack

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupbeginners @
categoriesperl
postedMay 13, '02 at 11:37p
activeMay 13, '02 at 11:48p
posts2
users1
websiteperl.org

1 user in discussion

Zachary Buckholz: 2 posts

People

Translate

site design / logo © 2023 Grokbase