Search pattern not terminated at (Spreadsheet::Read example)

J

Jorge

Using ActiveState perl 5.8.8 on XP, I'm attempting to use an example
from the Perl Hacks book by O'reilly.

It uses Spreadsheet::Read and simply retrieves the row and cell data
from a .xls file.

However, it throws this error ...

Search pattern not terminated at ...

and then points to this line ...

print join "\t" => map {$sheet->{cell}[$_][$row] // "-"} 1 ..
$sheet->{maxcol};

The only search pattern I see on this line is the 2 slashes (//) and as
far as I know, they are valid delimiters for search patterns and are
applied correctly. Can anyone shed some light on what this error could
mean?

I can post the complete program if needed.

Thank You

Jorge
 
P

Paul

The syntax is wrong. I'm not sure what // is supposed to be doing, but
whatever it is, it's wrong :)
 
J

Jorge

Paul said:
The syntax is wrong. I'm not sure what // is supposed to be doing, but
whatever it is, it's wrong :)

You are correct. Since my posting, I have tracked down that the // is
the Perl 6 construct for defined-or, not a set of pattern delimiters as
I had presumed. Now, I have to re-write that portion of code so it
plays in Perl 5.8.8 or look for a patch to Perl 5.8.8.

Thank you

Jorge
 
A

anno4000

Jorge said:
You are correct. Since my posting, I have tracked down that the // is
the Perl 6 construct for defined-or, not a set of pattern delimiters as
I had presumed. Now, I have to re-write that portion of code so it
plays in Perl 5.8.8 or look for a patch to Perl 5.8.8.

Replace (untested)

map {$sheet->{cell}[$_][$row] // "-"} 1 .. $sheet->{maxcol};

with

map defined ? $_ : '-', map $sheet->{cell}[$_][$row], 1 .. $sheet->{maxcol}

Btw, in the original code, the first slash is parsed as a division
operator. The second one seems to introduce an unterminated regex.

Anno
 
P

Paul

You are correct. Since my posting, I have tracked down that the // is
the Perl 6 construct for defined-or, not a set of pattern delimiters as
I had presumed.

No, defined-or is || so:

$foo ||= 'something';
 
D

Dr.Ruud

Paul schreef:
[attribution repaired] Jorge:
You are correct. Since my posting, I have tracked down that the // is
the Perl 6 construct for defined-or, not a set of pattern delimiters
as I had presumed.

No, defined-or is || so:

$foo ||= 'something';

You are confusing logical-or and defined-or. And your attribution
wasn't.
 
J

Jorge

Jorge said:
You are correct. Since my posting, I have tracked down that the // is
the Perl 6 construct for defined-or, not a set of pattern delimiters as
I had presumed. Now, I have to re-write that portion of code so it
plays in Perl 5.8.8 or look for a patch to Perl 5.8.8.

Replace (untested)

map {$sheet->{cell}[$_][$row] // "-"} 1 .. $sheet->{maxcol};

with

map defined ? $_ : '-', map $sheet->{cell}[$_][$row], 1 .. $sheet->{maxcol}

Btw, in the original code, the first slash is parsed as a division
operator. The second one seems to introduce an unterminated regex.

Anno

I agree the 2 slashes are being parsed incorectly.

This is the correction which works.

print join "\t" => map
{
my $val = $sheet->{cell}[$_][$row];
defined $val ? $val : "-";
} 1 .. $sheet->{maxcol};

Thanks very much for all the responses.
 

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,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top