CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Perl - search pattern not terminated at line x

 



dr057
New User

Apr 29, 2015, 7:10 AM

Post #1 of 8 (4552 views)
Perl - search pattern not terminated at line x Can't Post

Hi, I have the following perl code and it runs fine on my redhat linux laptop but when i run same code on redhat server I get 'search pattern not terminated at line 15'

This is line 15:

$seen{$id}{$user} = [$date, $.] if $date gt ($seen{$id}{$user}[0] // q());

code starts here:

my %seen;
while (<>) {
my ($id, $user, $date) = split /;/;
$seen{$id}{$user} = [$date, $.] if $date gt ($seen{$id}{$user}[0] // q());
}

my @l = sort { $a->[3] <=> $b->[3] } # Sort by line number.
map { my $id = $_; map [ $id, $_, @{ $seen{$id}{$_} } ],
keys %{ $seen{$_} }
}
keys %seen;
print join ';', @{$_}[0, 1, 2] for @l;

Any help would be appreciated, thx!


FishMonger
Veteran / Moderator

Apr 29, 2015, 9:50 AM

Post #2 of 8 (4544 views)
Re: [dr057] Perl - search pattern not terminated at line x [In reply to] Can't Post

What version of perl are you running on each system?

If I'm not not mistaken, the // defined-or operator was not available prior to v5.10. I suspect that you're running 5.8.x on the server.


(This post was edited by FishMonger on Apr 29, 2015, 9:51 AM)


dr057
New User

Apr 29, 2015, 10:05 AM

Post #3 of 8 (4540 views)
Re: [FishMonger] Perl - search pattern not terminated at line x [In reply to] Can't Post

Your correct, my laptop is at version 5.10, server is at version 5.8.8, is there any substitution you know of for // or would the server have to be updated?

Thanks FishMonger!


FishMonger
Veteran / Moderator

Apr 29, 2015, 11:11 AM

Post #4 of 8 (4533 views)
Re: [dr057] Perl - search pattern not terminated at line x [In reply to] Can't Post

The best solution would be to upgrade perl, the next best solution would be to apply the patch that adds the // operator, and the last choice and easiest would be to adjust the syntax to what is supported under v5.8.


Code
$seen{$id}{$user}[0] // q()

Is the same as:

Code
defined $seen{$id}{$user}[0] ? $seen{$id}{$user}[0] : q()



(This post was edited by FishMonger on Apr 29, 2015, 11:13 AM)


dr057
New User

Apr 29, 2015, 11:35 AM

Post #5 of 8 (4529 views)
Re: [FishMonger] Perl - search pattern not terminated at line x [In reply to] Can't Post

Okay, got it.. I think best is upgrade also. Thanks again, appreciate your help on this!


Laurent_R
Veteran / Moderator

Apr 29, 2015, 11:47 PM

Post #6 of 8 (4519 views)
Re: [dr057] Perl - search pattern not terminated at line x [In reply to] Can't Post

If you can be guaranteed that, when defined, $seen{$id}{$user}[0] will always return a true value (i.e. never 0, nor "0", nor an empty string), then you could change the test:

Code
$seen{$id}{$user}[0] // q()

to this:

Code
$seen{$id}{$user}[0] || q()

I think it should work under 5.8.


(This post was edited by Laurent_R on Apr 29, 2015, 11:49 PM)


shawnhcorey
Enthusiast


Apr 30, 2015, 5:47 AM

Post #7 of 8 (4513 views)
Re: [dr057] Perl - search pattern not terminated at line x [In reply to] Can't Post


In Reply To

Code
$seen{$id}{$user} = [$date, $.] if $date gt ($seen{$id}{$user}[0] // q());



Would this be a better solution?


Code
$seen{$id}{$user} = [$date, $.] if defined( $seen{$id}{$user}[0] ) && $date gt $seen{$id}{$user}[0]


But to avoid autovivification:

Code
if(  defined( $seen{$id} ) 
&& defined( $seen{$id}{$user} )
&& defined( $seen{$id}{$user}[0] )
&& $date gt $seen{$id}{$user}[0]
){
$seen{$id}{$user} = [$date, $.];
}


__END__

I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".


dr057
New User

May 2, 2015, 2:22 PM

Post #8 of 8 (4180 views)
Re: [shawnhcorey] Perl - search pattern not terminated at line x [In reply to] Can't Post

Thanks Shawn, I'll give it a try..

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives