in reply to Re: split a line into 2 variables and store in SQL
in thread split a line into 2 variables and store in SQL

Thanks for ur reply... But still I have some doubt... I tried using
@words = split(/<=/, $_); print "$_"; $sth->execute(@words[0], @words[1]) or die $DBI::errstr;}
But its not working... And will this work to store all the data into the sql table?? Thanks,

Replies are listed 'Best First'.
Re^3: split a line into 2 variables and store in SQL
by Bloodnok (Vicar) on Jan 23, 2009 at 11:04 UTC
    AFAICS, you wouldn't expect a statement of the form apple banana to work as its clearly not valid SQL - unless there's something I've missed in the postings thus far ...

    Maybe some sample output, failing though it is, would help us (to help you)

    A user level that continues to overstate my experience :-))
      Hi Bloodnok, Thanks for your reply...I have a file in which i have data..
      word1 := word2; word3 <= word4; word5 <= word6;
      And i have to read this... such that i read word1, word3, word 5.. etc in same variable so that i should be able to transfer this data into a SQL table. And as far as i knw, we can transfer any data into the sql. Thanking you,
        ...but you can only update an SQL table using an SQL UPDATE statement e.g.
        UPDATE table SET foo = bar WHERE condition
        browsing SQL should start you off.

        BTW, you do realise that the split you perform won't work with word1 := word2; since the value you split on doesn't exist, try /\s*.=\s/* as the regex - in that way, you'll remove white space either side of the tokens you actually want.

        Alternatively, just use vanilla split and use the 1st and 3rd elements of the resulting array e.g.

        while (<>) { my @args = split; # Now use $args[0] & $args[2] as appropriate . . }

        A user level that continues to overstate my experience :-))
Re^3: split a line into 2 variables and store in SQL
by moritz (Cardinal) on Jan 23, 2009 at 12:20 UTC
    @words[0]

    No! I wrote $words[0], and with reasons.

    But its not working
    How is it not working? What's the error message (or the error condition that you observe)?
      Hi Moritz, Infact its partially working... Actually i am trying to transfer the data twice to the sql... my code is something like this:
      if(condition1){ @words = split(/=/, $_); print "$_"; $sth->execute($words[0],$words[1]) or die $DBI::errstr; } if(condition2){ @words = split(/=/, $_); print "$_"; $sth->execute($words[0],$words[1]) or die $DBI::errstr;}
      For the condition1 its working fine.. But as soon as i try with condition2 it shows some error abt missing curl bracket in some other loop. But if i try to use $_, $_ in second condition its works fine. Dont knw wats the problem is..
      if(condition1){ @words = split(/=/, $_); print "$_"; $sth->execute($words[0],$words[1]) or die $DBI::errstr; } if(condition2){ @words = split(/=/, $_); print "$_"; $sth->execute($_,$_) or die $DBI::errstr;}
      Infact if i use $words[0], $_. Then also it does not show any error. But as soon as I try with $words[0], $words1, it starts showing the error..
      DBD::mysql::st execute failed: Column 'name' cannot be null at ./fsm0. +pl line 110, <> line 170. Column 'name' cannot be null at ./fsm0.pl line 110, <> line 170.
      Thanking you,
        And which one is line 110 in your script now?