2 dimentional data call within a conditional

F

fzxdf5

Greetings,

I am trying to get this snippet to run...but it fails at the
conditional "if" portion.

I think the problem lies in the ...m/\$data[$r][0]\b/...build
portion. I've even 'built" the search expression around a non-arrayed
variable with no luck

What am I doing wrong?

@data= ( ["junk",3,1,3,4], ["trash",4,2,3,4,6] );

@money = ( "junk", "trash");

for ($r=0; $r<2; $r++)
{
if ($money[$r] =~ m/\$data[$r][0]\b/ )
{
print "data[$r][0] = $data[$r]->[0]\n";
}
}
 
J

J. Gleixner

Greetings,

I am trying to get this snippet to run...but it fails at the
conditional "if" portion.

What fails?
I think the problem lies in the ...m/\$data[$r][0]\b/...build
portion. I've even 'built" the search expression around a non-arrayed
variable with no luck

No idea what a 'build portion' is..
What am I doing wrong?

use strict;
use warnings;
@data= ( ["junk",3,1,3,4], ["trash",4,2,3,4,6] );

@money = ( "junk", "trash");

for ($r=0; $r<2; $r++)
{
if ($money[$r] =~ m/\$data[$r][0]\b/ )
^ no need to escape the '$'.
if ($money[$r] =~ m/$data[$r][0]\b/ )

Why use a match at all??

if( $money[ $r ] eq $data[$r][0] )
{
print "data[$r][0] = $data[$r]->[0];
print "data[$r][0]=$data[$r][0]\n";
 
F

fzxdf5

Greetings,
I am trying to get this snippet to run...but it fails at the
conditional "if" portion.

What fails?


I think the problem lies in the ...m/\$data[$r][0]\b/...build
portion. I've even 'built" the search expression around a non-arrayed
variable with no luck

No idea what a 'build portion' is..


What am I doing wrong?

use strict;
use warnings;


@data= ( ["junk",3,1,3,4], ["trash",4,2,3,4,6] );
@money = ( "junk", "trash");
for ($r=0; $r<2; $r++)
{
if ($money[$r] =~ m/\$data[$r][0]\b/ )

^ no need to escape the '$'.
if ($money[$r] =~ m/$data[$r][0]\b/ )

Why use a match at all??

if( $money[ $r ] eq $data[$r][0] )
{
print "data[$r][0] = $data[$r]->[0];

print "data[$r][0]=$data[$r][0]\n";


}
}- Hide quoted text -

- Show quoted text -

Thank you for your quick reply...I see what you mean with a complete
field match. This pointed out an error in my provided snippet of what
I'm trying to extract from the array

In my original snippet...I made an error in my $data line
presentation...it should have read

@data= ( ["crushed junk car",3,1,3,4], ["green trash can",
4,2,3,4,6] );

where I'm searching for a string segment in the first array position.

Sorry about this oversite.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top