shawn wilson wrote:
this is pretty abstract from what i'm really doing, but i'll put in
the blurb anyway...

i'm using CAM::PDF to parse data. this works well. however, i am
trying to extract information out of a table. so, i want to find
certain keys, then go up 3 levels and grab the position of that peace
of data so that i can then search for text with that same horizontal
or vertical position (defined in two other refs on the same level of a
different 'branch'). so, what i want is an array ref with the number
of found keys with the refs it took to get there. i've liked
Data::Walk but i couldn't figure out how to return the results - all i
could do is 'print'. and i couldn't figure out how to use
Data::Visitor either. so, i figured i'd try myself.

a few things i don't understand here:
does the second print cut off?
when i pass $tree instead of \$tree, it gives me this:
CAM::PDF::Content=HASH(0x2b298a8) is CAM::PDF::Content LEVEL: 0 FOUND:
0 CLEAR: 0
where CAM::PDF::Content isn't going to match anything. how do i handle this?
obviously i'm not thinking clearly about how i need to build
$datdepth. and ideally, i'd like the value to be internal to the sub
and returned when it is finished instead of global. any help with my
thinking would be great.

so, here's where i'm at:

[ SNIP some code ]


    if( ( ref( $data ) or $data ) eq 'SCALAR' ) {

    } elsif( ( ref( $data ) or $data ) eq 'HASH' ) {

    } elsif( ( ref( $data ) or $data ) eq 'ARRAY' ) {

    } elsif( ( ref( $data ) or $data ) eq 'REF' ) {

    } elsif( ( ref( $data ) or $data ) ne ( 'SCALAR' or 'HASH' or 'ARRAY' ) ) {


Those comparisons are not going to work, or at least not in the way you probably intended.

$ perl -le' print "It did ", ( $ARGV[0] or $ARGV[1] ) eq "TEST" ? "" : "NOT ", "work." ' a b
It did NOT work.
$ perl -le' print "It did ", ( $ARGV[0] or $ARGV[1] ) eq "TEST" ? "" : "NOT ", "work." ' a TEST
It did NOT work.
$ perl -le' print "It did ", ( $ARGV[0] or $ARGV[1] ) eq "TEST" ? "" : "NOT ", "work." ' TEST b
It did work.


You have to do it like this:

$ perl -le' print "It did ", $ARGV[0] eq "TEST" || $ARGV[1] eq "TEST" ? "" : "NOT ", "work." ' a b
It did NOT work.
$ perl -le' print "It did ", $ARGV[0] eq "TEST" || $ARGV[1] eq "TEST" ? "" : "NOT ", "work." ' a TEST
It did work.
$ perl -le' print "It did ", $ARGV[0] eq "TEST" || $ARGV[1] eq "TEST" ? "" : "NOT ", "work." ' TEST b
It did work.


As to the last example you probably need something like this:

} elsif ( grep( $_ ne ref $data, 'SCALAR', 'HASH', 'ARRAY' ) || grep( $_ ne $data, 'SCALAR', 'HASH', 'ARRAY' ) ) {




John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to