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

Since you store the result of the split in the array @word, you actually have to use it:
$sth->execute($words[0], $words[1]) or die $DBI::errstr;

(As a side node $1 is not a register, but a (special) variable that is set by the regex engine.

Replies are listed 'Best First'.
Re^2: split a line into 2 variables and store in SQL
by sharan (Acolyte) on Jan 23, 2009 at 10:56 UTC
    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,
      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,
      @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,