For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > June 2007 > 2 dimentional data call within a conditional









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author 2 dimentional data call within a conditional
fzxdf5@gmail.com

2007-06-28, 7:05 pm

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. Gleixner

2007-06-28, 7:05 pm

fzxdf5@gmail.com wrote:
> 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";


> }
> }
>

fzxdf5@gmail.com

2007-06-29, 7:03 pm

On Jun 28, 4:49 pm, "J. Gleixner" <glex_no-s...@qwest-spam-no.invalid>
wrote:
> fzx...@gmail.com wrote:
>
>
> What fails?
>
>
>
>
> No idea what a 'build portion' is..
>
>
>
>
> use strict;
> use warnings;
>
>
>
>
>
>
> ^ 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]\n";
>
>
>
>
> - 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.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com