Question

I have a simple Perl program which just concatenates a string read from file to a prefix 'qr'

  my $regex = eval 'qr'.$line;   
  my $myLength = length($regex);
  print "Length of string: $myLength\n";

With the size of $line is quite big (~100000 characters). It seems like eval just refuses to work. What i got for $myLength is just 0 while I still can print $line. Do you have any suggestion for that issue?

Thanks,

Was it helpful?

Solution

Perl eval does not have such a limit; the following works for me with no error, for instance:

my $line = '/' . 'x' x 100000 . '/';
my $regex = eval 'qr' . $line;
print "error: $@\n" if $@;
my $myLength = length($regex);
print "Length of string: $myLength\n";

output:

Length of string: 100005

You have something wrong in your input; examine $@ after the eval to see what.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top