INDEX Function
am 10.09.2007 19:34:44 von amerar
Ok, I should be able to figure this out, but guess not.
I have a long string here, and I'm using the INDEX function to find a
string within that. Why then, is it always returning the wrong
position??? Here are some examples. I'm looking for the string "
AND ", notice the capital letters.
Here is my INDEX statement:
for $i (0 .. $#info) {
$customer_id = $info[$i][0];
$screen_name = $info[$i][1];
$screen_query = substr($info[$i][2],4);
$and = index($screen_query, 'AND');
print "AND POSITION IS HERE: $and\n";
}
POSITION IS HERE: 8
HERE: 20,1115,1082,1083,1086,1088,1089,1090|select
master_table.ticker,master_table.comp_name,DIV_YIELD,NET_MAR GIN,DEBT_TO_EQUITY,PRICE_TO_BOOK,PRICE_TO_CASH,PRICE_TO_SALE S
from master_table,prices,stock_data,daily_zacks_rank where
master_table.m_ticker=stock_data.m_ticker and
master_table.m_ticker=prices.m_ticker and
master_table.m_ticker=daily_zacks_rank.m_ticker AND
upper(PRICE_TO_BOOK) <= 1.2 AND upper(PRICE_TO_CASH) >= 1.5 AND
upper(PRICE_TO_SALES) <= 1.2
POSITION IS HERE: 38
HERE: 20,1115|select master_table.ticker,master_table.comp_name from
master_table,prices,stock_data,daily_zacks_rank where
master_table.m_ticker=stock_data.m_ticker and
master_table.m_ticker=prices.m_ticker and
master_table.m_ticker=daily_zacks_rank.m_ticker AND upper(DIV_YIELD)
>= 4 AND upper(DEBT_TO_EQUITY) <= .2
POSITION IS HERE: 381
HERE:
16\1020,1021,1024,1028,1115,1030,1032,1033,1040,1042,1055,10 56,1057,1065,1073,1078|
select
master_table.ticker,stock_data.EXCHANGE,stock_data.SECTOR_NA ME,stock_data.MKT_VALUE,master_table.comp_name,prices.CLOSIN G,stock_data.HIGH_52W,stock_data.LOW_52W,daily_zacks_rank.z_ rank_d,AVG_RATING,Q_EST_SURP,SURP_PREV,SURP_AVG_4Q,NET_PERC_ INS,TREND_EPGR,PE_12M
from master_table,prices,stock_data,daily_zacks_rank where
master_table.m_ticker=stock_data.m_ticker and
master_table.m_ticker=prices.m_ticker and
master_table.m_ticker=daily_zacks_rank.m_ticker(+) AND
upper(daily_zacks_rank.z_rank_d) <= 2 AND upper(AVG_RATING) <= 2 AND
upper(Q_EST_SURP) >= 0 AND upper(SURP_PREV) >= 0 AND
upper(SURP_AVG_4Q) >= 0 AND upper(stock_data.MKT_VALUE) >= 500 AND
upper(stock_data.PERC_CHG_12W) >= 10 AND upper(PRICE_TO_SALES) <= .5
Go figure???
Re: INDEX Function
am 10.09.2007 19:47:55 von glex_no-spam
amerar@iwc.net wrote:
> Ok, I should be able to figure this out, but guess not.
>
> I have a long string here, and I'm using the INDEX function to find a
> string within that. Why then, is it always returning the wrong
> position??? Here are some examples. I'm looking for the string "
> AND ", notice the capital letters.
No it's looking for 'AND'.
>
> Here is my INDEX statement:
>
> for $i (0 .. $#info) {
> $customer_id = $info[$i][0];
> $screen_name = $info[$i][1];
> $screen_query = substr($info[$i][2],4);
>
> $and = index($screen_query, 'AND');
> print "AND POSITION IS HERE: $and\n";
> }
>
> POSITION IS HERE: 8
> HERE: 20,1115,1082,1083,1086,1088,1089,1090|select
Since you don't show us what's in $screen_query, how
can we help? Your output never contains
'AND POSITION IS HERE: ' either. Post actual
code that others can run which shows your issue.
e.g.
my $screen_query='blah..';
my $pos = index($screen_query, 'AND');
print "AND POSITION IS HERE: $pos\n" if $pos >= 0;
Re: INDEX Function
am 10.09.2007 20:06:33 von amerar
On Sep 10, 12:47 pm, "J. Gleixner"
no.invalid> wrote:
> ame...@iwc.net wrote:
> > Ok, I should be able to figure this out, but guess not.
>
> > I have a long string here, and I'm using the INDEX function to find a
> > string within that. Why then, is it always returning the wrong
> > position??? Here are some examples. I'm looking for the string "
> > AND ", notice the capital letters.
>
> No it's looking for 'AND'.
>
>
>
> > Here is my INDEX statement:
>
> > for $i (0 .. $#info) {
> > $customer_id = $info[$i][0];
> > $screen_name = $info[$i][1];
> > $screen_query = substr($info[$i][2],4);
>
> > $and = index($screen_query, 'AND');
> > print "AND POSITION IS HERE: $and\n";
> > }
>
> > POSITION IS HERE: 8
> > HERE: 20,1115,1082,1083,1086,1088,1089,1090|select
>
> Since you don't show us what's in $screen_query, how
> can we help? Your output never contains
> 'AND POSITION IS HERE: ' either. Post actual
> code that others can run which shows your issue.
>
> e.g.
>
> my $screen_query='blah..';
> my $pos = index($screen_query, 'AND');
> print "AND POSITION IS HERE: $pos\n" if $pos >= 0;
$screen_query is the SQL query you see. The extremely long string.
Here is the code:
for $i (0 .. $#info) {
$customer_id = $info[$i][0];
$screen_name = $info[$i][1];
$screen_query = $info[$i][2];
print "HERE: $screen_query\n\n";
$string = 'select';
$d = index($screen_query, $string);
print "POSITION IS HERE: $d\n";
}
Re: INDEX Function
am 10.09.2007 20:17:07 von glex_no-spam
amerar@iwc.net wrote:
> On Sep 10, 12:47 pm, "J. Gleixner"
> no.invalid> wrote:
>> ame...@iwc.net wrote:
>>> Ok, I should be able to figure this out, but guess not.
>>> I have a long string here, and I'm using the INDEX function to find a
>>> string within that. Why then, is it always returning the wrong
>>> position??? Here are some examples. I'm looking for the string "
>>> AND ", notice the capital letters.
>> No it's looking for 'AND'.
>>
>>
>>
>>> Here is my INDEX statement:
>>> for $i (0 .. $#info) {
>>> $customer_id = $info[$i][0];
>>> $screen_name = $info[$i][1];
>>> $screen_query = substr($info[$i][2],4);
>>> $and = index($screen_query, 'AND');
>>> print "AND POSITION IS HERE: $and\n";
>>> }
>>> POSITION IS HERE: 8
>>> HERE: 20,1115,1082,1083,1086,1088,1089,1090|select
>> Since you don't show us what's in $screen_query, how
>> can we help? Your output never contains
>> 'AND POSITION IS HERE: ' either. Post actual
>> code that others can run which shows your issue.
>>
>> e.g.
>>
>> my $screen_query='blah..';
>> my $pos = index($screen_query, 'AND');
>> print "AND POSITION IS HERE: $pos\n" if $pos >= 0;
>
> $screen_query is the SQL query you see. The extremely long string.
> Here is the code:
>
> for $i (0 .. $#info) {
> $customer_id = $info[$i][0];
> $screen_name = $info[$i][1];
> $screen_query = $info[$i][2];
> print "HERE: $screen_query\n\n";
>
> $string = 'select';
> $d = index($screen_query, $string);
> print "POSITION IS HERE: $d\n";
> }
>
One last time...
*Post actual code that others can run which shows your issue.*
my $screen_query = ' some long string with select in it';
my $string = 'select';
my $d = index($screen_query, $string);
print "POSITION IS HERE: $d\n";
POSITION IS HERE: 23
Re: INDEX Function
am 10.09.2007 20:20:45 von amerar
On Sep 10, 1:17 pm, "J. Gleixner"
wrote:
> ame...@iwc.net wrote:
> > On Sep 10, 12:47 pm, "J. Gleixner"
> > no.invalid> wrote:
> >> ame...@iwc.net wrote:
> >>> Ok, I should be able to figure this out, but guess not.
> >>> I have a long string here, and I'm using the INDEX function to find a
> >>> string within that. Why then, is it always returning the wrong
> >>> position??? Here are some examples. I'm looking for the string "
> >>> AND ", notice the capital letters.
> >> No it's looking for 'AND'.
>
> >>> Here is my INDEX statement:
> >>> for $i (0 .. $#info) {
> >>> $customer_id = $info[$i][0];
> >>> $screen_name = $info[$i][1];
> >>> $screen_query = substr($info[$i][2],4);
> >>> $and = index($screen_query, 'AND');
> >>> print "AND POSITION IS HERE: $and\n";
> >>> }
> >>> POSITION IS HERE: 8
> >>> HERE: 20,1115,1082,1083,1086,1088,1089,1090|select
> >> Since you don't show us what's in $screen_query, how
> >> can we help? Your output never contains
> >> 'AND POSITION IS HERE: ' either. Post actual
> >> code that others can run which shows your issue.
>
> >> e.g.
>
> >> my $screen_query='blah..';
> >> my $pos = index($screen_query, 'AND');
> >> print "AND POSITION IS HERE: $pos\n" if $pos >= 0;
>
> > $screen_query is the SQL query you see. The extremely long string.
> > Here is the code:
>
> > for $i (0 .. $#info) {
> > $customer_id = $info[$i][0];
> > $screen_name = $info[$i][1];
> > $screen_query = $info[$i][2];
> > print "HERE: $screen_query\n\n";
>
> > $string = 'select';
> > $d = index($screen_query, $string);
> > print "POSITION IS HERE: $d\n";
> > }
>
> One last time...
> *Post actual code that others can run which shows your issue.*
>
> my $screen_query = ' some long string with select in it';
> my $string = 'select';
> my $d = index($screen_query, $string);
> print "POSITION IS HERE: $d\n";
>
> POSITION IS HERE: 23
Ok, I am writing this script myself, no one else will run it. I
simply query an Oracle database and return what is in $screen_query.
You saw those values in my first post. Those were the long values.
Then, I am looking for the first occurrence of the work ' AND '. The
perl code to loop through the array is below. Thee is nothing more to
it..........
for $i (0 .. $#info) {
$customer_id = $info[$i][0];
$screen_name = $info[$i][1];
$screen_query = $info[$i][2];
print "HERE: $screen_query\n\n";
$string = ' AND ';
$d = index($screen_query, $string);
print "POSITION IS HERE: $d\n";
If you need to see the values of $query_string, there they are again:
POSITION IS HERE: 8
HERE: 20,1115,1082,1083,1086,1088,1089,1090|select
master_table.ticker,master_table.comp_name,DIV_YIELD,NET_MAR GIN,DEBT_TO_EQUITY,PRICE_TO_BOOK,PRICE_TO_CASH,PRICE_TO_SALE S
from master_table,prices,stock_data,daily_zacks_rank where
master_table.m_ticker=stock_data.m_ticker and
master_table.m_ticker=prices.m_ticker and
master_table.m_ticker=daily_zacks_rank.m_ticker AND
upper(PRICE_TO_BOOK) <= 1.2 AND upper(PRICE_TO_CASH) >= 1.5 AND
upper(PRICE_TO_SALES) <= 1.2
POSITION IS HERE: 38
HERE: 20,1115|select master_table.ticker,master_table.comp_name from
master_table,prices,stock_data,daily_zacks_rank where
master_table.m_ticker=stock_data.m_ticker and
master_table.m_ticker=prices.m_ticker and
master_table.m_ticker=daily_zacks_rank.m_ticker AND upper(DIV_YIELD)
>= 4 AND upper(DEBT_TO_EQUITY) <= .2
POSITION IS HERE: 381
HERE:
16\1020,1021,1024,1028,1115,1030,1032,1033,1040,1042,1055,10 56,1057,1065,1073,1078|
select
master_table.ticker,stock_data.EXCHANGE,stock_data.SECTOR_NA ME,stock_data.MKT_VALUE,master_table.comp_name,prices.CLOSIN G,stock_data.HIGH_52W,stock_data.LOW_52W,daily_zacks_rank.z_ rank_d,AVG_RATING,Q_EST_SURP,SURP_PREV,SURP_AVG_4Q,NET_PERC_ INS,TREND_EPGR,PE_12M
from master_table,prices,stock_data,daily_zacks_rank where
master_table.m_ticker=stock_data.m_ticker and
master_table.m_ticker=prices.m_ticker and
master_table.m_ticker=daily_zacks_rank.m_ticker(+) AND
upper(daily_zacks_rank.z_rank_d) <= 2 AND upper(AVG_RATING) <= 2 AND
upper(Q_EST_SURP) >= 0 AND upper(SURP_PREV) >= 0 AND
upper(SURP_AVG_4Q) >= 0 AND upper(stock_data.MKT_VALUE) >= 500 AND
upper(stock_data.PERC_CHG_12W) >= 10 AND upper(PRICE_TO_SALES) <= .5
Re: INDEX Function
am 10.09.2007 20:33:09 von xhoster
"amerar@iwc.net" wrote:
>
> $screen_query is the SQL query you see. The extremely long string.
> Here is the code:
>
> for $i (0 .. $#info) {
> $customer_id = $info[$i][0];
> $screen_name = $info[$i][1];
> $screen_query = $info[$i][2];
> print "HERE: $screen_query\n\n";
>
> $string = 'select';
You are not searching for "AND" (notice case or not), you are searching
for "select".
> $d = index($screen_query, $string);
> print "POSITION IS HERE: $d\n";
You are printing the sql string before you are printing the position, while
in your example you started the "example" output out with the position
(apparently from an incomplete prior iteration), not the sql string. Once
one realizes that you are out of register, and searching for something
different than you claim you are searching for, and apparently posted the
wrong code in the first place, then your example output seems to be what
one would expect it to be.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
Re: INDEX Function
am 10.09.2007 20:45:50 von amerar
On Sep 10, 1:33 pm, xhos...@gmail.com wrote:
> "ame...@iwc.net" wrote:
>
> > $screen_query is the SQL query you see. The extremely long string.
> > Here is the code:
>
> > for $i (0 .. $#info) {
> > $customer_id = $info[$i][0];
> > $screen_name = $info[$i][1];
> > $screen_query = $info[$i][2];
> > print "HERE: $screen_query\n\n";
>
> > $string = 'select';
>
> You are not searching for "AND" (notice case or not), you are searching
> for "select".
>
> > $d = index($screen_query, $string);
> > print "POSITION IS HERE: $d\n";
>
> You are printing the sql string before you are printing the position, while
> in your example you started the "example" output out with the position
> (apparently from an incomplete prior iteration), not the sql string. Once
> one realizes that you are out of register, and searching for something
> different than you claim you are searching for, and apparently posted the
> wrong code in the first place, then your example output seems to be what
> one would expect it to be.
>
> Xho
>
> --
> --------------------http://NewsReader.Com/------------------ --
> The costs of publication of this article were defrayed in part by the
> payment of page charges. This article must therefore be hereby marked
> advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
> this fact.
That was my fault. I was trying different strings to see what kind of
results I'd get and in my copying and pasting, I probably messed
things up.
But in any case, I even printed out the length, and it is wrong, with
no patterns. Maybe there is a character in the string messing things
up???
Re: INDEX Function
am 11.09.2007 09:52:17 von Dave Weaver
On Mon, 10 Sep 2007 11:20:45 -0700, amerar@iwc.net wrote:
> On Sep 10, 1:17 pm, "J. Gleixner"
> wrote:
> > One last time...
> > *Post actual code that others can run which shows your issue.*
> >
>
> Ok, I am writing this script myself, no one else will run it.
You are missing the point.
If you would like people here on clpm to help you solve your problem
you must show us a small-but-runnable piece of code AND data that
exhibits the problem you are seeing. Make sure you use strict and
warnings too.
For example:
#!/usr/bin/perl
use strict;
use warnings;
my $screen_query = <
20,1115,1082,1083,1086,1088,1089,1090|select
master_table.ticker,master_table.comp_name,DIV_YIELD,NET_MAR GIN,
DEBT_TO_EQUITY,PRICE_TO_BOOK,PRICE_TO_CASH,PRICE_TO_SALES
from master_table,prices,stock_data,daily_zacks_rank where
master_table.m_ticker=stock_data.m_ticker and
master_table.m_ticker=prices.m_ticker and
master_table.m_ticker=daily_zacks_rank.m_ticker AND
upper(PRICE_TO_BOOK) <= 1.2 AND upper(PRICE_TO_CASH) >= 1.5 AND
upper(PRICE_TO_SALES) <= 1.2
END
my $string = ' AND ';
my $d = index($screen_query, $string);
print "POSITION IS HERE: $d\n";
If you cut-and-paste the above program into perl you see the output:
POSITION IS HERE: 394
Now, please show us a sample of the problem you are having, in the
same way.