How can I fix this error:
[Fri Dec 11 12:07:24.417565 2015] [cgi:error] [pid 10838] [client 24.32.36.240:54536] AH01215: [Fri Dec 11 12:07:24 2015]
uu_upload.pl: Use of uninitialized value in numeric eq (==) at uu_upload.pl line 350.: /home/public_html/cgi-bin/uu_upload.pl,
referer: http://www.....com/uploader.php
Line 349 - Line 353 shows:
# Force 'redirect_using_location' if user does not have a javascript capable browser or using embedded_upload_results
if($query->param('no_script') || $query->param('embedded_upload_results') == 1){
$main::config->{redirect_using_js_html} = 0;
$main::config->{redirect_using_location} = 1;
}
Any assistance will be appreciated.
Using the defined function you can check the variable is defined.
if ( defined($variable) && $variable == 10 ) {
...
}
Related
This question already has answers here:
How to declare function and use it recursively without "called too early to check prototype"
(2 answers)
Closed 1 year ago.
How to solve Perl error comes up when recursive function running
main::getE_Path_Rec() called too early to check prototype at ./test.pl line 28
shown by cat -n:
13 our ($whole, #result);
14
15 sub getE_Path_Rec ($\#$) { my ($path, #iOffNode, $offset) = #_;
16
17 $path=~ s#^/([^/]+)(.*)$#$2#;
18 my #OffNode; my $eleNow=$1;
19 for (#iOffNode) {
20 $eleNow=~ m#^([^[/,]+)(?|\[(\d+|#[^]]+)\]|,(\d+))?#;
21 #
22 if($2) {
23 getElem($1, $2-1, $_->[1], #OffNode);
24 return undef if !#OffNode;
25 if ($path) {
26 #
27 #
28 getE_Path_Rec( $path, #OffNode, $offset.${$OffNode[0]}[0])
29 }else {
30 push( #result, [$offset, ${$OffNode[0]}[1]])
31 }
36 }
37
38 return
39 }
How do we solve such in Perl up to the recursive function seamlessly ?
The docs for prototype in perlsub spell this out
... a recursive function with a prototype has to be predeclared for the prototype to take effect
So need
sub getE_Path_Rec ($\#$); # predeclare
# later
sub getE_Path_Rec ($\#$) { ... } # actual definition
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I have written a Perl subroutine that is supposed to take the name of a month and return a number if it matches, otherwise returning the original argument if not.
sub convert_month_to_number {
my ($input) = #_;
my #month_names = qw/January February March April May June July August September October November December/;
my #month_names_short = qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/;
for (my $i = 0; $i < scalar(#month_names); $i = $i + 1){
print "$month_names[$i]\n";
if ($input == $month_names[$i]{
return $i;
}
}
return $input;
}
}
However, when compiling this in Padre I receive the error:
syntax error at additionalscripts.pl line 16, near "}"
Global symbol "$input" requires explicit package name at additionalscripts.pl li
ne 19.
syntax error at additionalscripts.pl line 20, near "}"
Execution of additionalscripts.pl aborted due to compilation errors.
I'm not exactly sure why this is occurring, considering how I've already declared $input as a global variable up top. Any help would be greatly appreciated. I'm currently using Perl 5.010 on Windows.
You had a few errors in your code, which I've cleaned up.
my #test = qw(Foo January Bar);
say convert_month_to_number($_) foreach #test;
sub convert_month_to_number {
my ($input) = shift;
my #month_names = qw/January February March April May June July August September October November December/;
my #month_names_short = qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/;
for (my $i = 0; $i < #month_names; $i++){
if ($month_names[$i] eq $input){
return $i;
}
}
return $input;
}
Here's my code..I am trying to create a hash lookup table and access the data from it in every loop..
#! usr/bin/perl
use warnings;
use strict;
sub bin2dec
{
return unpack("N", pack("B32", substr("0" x 32 . shift, -32)));
}
while(<>)
{
if(/SIB_DBG/)
{
if(/TTRB:\s*([\da-f]+)\s([\da-f]+)\s([\da-f]+)\s([\da-f]+)/ ||
/ETRB:\s*([\da-f]+)\s([\da-f]+)\s([\da-f]+)\s([\da-f]+)/ ||
/Command\sETRB\s*([\da-f]+)\s([\da-f]+)\s([\da-f]+)\s([\da-f]+)/ )
{
print "$_ $1 $2 $3 $4\n";
my $deci1 = hex($1);
my $deci2 = hex($2);
my $deci3 = hex($3);
my $deci4 = hex($4);
my $bin = reverse sprintf("%032b",$deci4); #convert to 32 bit binary and reverse
print "\nbinary :$bin\n";
my $sub = substr($bin ,16,6); #extract required 6 bits
print "string :$sub\n";
my $type = bin2dec($sub);
my $val = $trb{"$type"};
print "TRB type: $type\n";
print "detail: $val\n";
}
}
}
my %trb = (
0 => "reserved",
32 => "transfer event",
48 => "vendor defined");
but I am getting an error even if I have declared trb .
Global symbol "%trb" requires explicit package name at script.plx line 31.
Execution of script.plx aborted due to compilation errors.
Again my input log file is like
Aug 31 15:25:53 usb3 kernel: [ 78.684054] SIB_DBG TTRB:00000000 00000000 00000000 00002401, PTR: ffff88005ff8b000
Aug 31 15:25:53 usb3 kernel: [ 78.815428] SIB_DBG ETRB: 5ff8b850 00000000 01000000 01018001
You are using the hash %trb in this line:
my $val = $trb{"$type"};
before you have declared %trb here:
my %trb = (
0 => "reserved",
32 => "transfer event",
48 => "vendor defined");
Move that declaration of %trb up above the while loop.
The hash %trb must be declared before it is used. Move its definition up to before the while statement -- after your subroutine defintion and all will be well
You appear to be more familiar with a different language, as you usually find Perl subroutines at the end of the program, but it doesn't matter either way
As per below script, Trying to give two Input files. Test_DDD111_20120731.csv and DDD111.txt.
Inside one folder this Test_DDD111*.csv file with different date will be available. I want to give only current date file as input inside this script.
I assign date as $deviationreportdate. But i am getting error, can anyone help me to solve this problem.
Error which i am getting:
Scalar found where operator expected at subscriberdump.pl line 58, near "/Test_DDD(\d+)/${deviationreportdate}"
(Missing operator before ${deviationreportdate}?)
syntax error at subscriberdump.pl line 58, near "/Test_DDD(\d+)/${deviationreportdate}"
Execution of test.pl aborted due to compilation errors.
#!/usr/bin/perl
use strict;
use warnings;
use strict;
use POSIX;
my #array123;
my $daysbefore;
my %month="";
my ($f2_field, #patterns, %patts, $f2_rec);
while (#ARGV)
{
my $par=shift;
if( $par eq "-d" )
{
$daysbefore=shift;
next;
}
}
sub getDate
{
my $daysago=shift;
$daysago=0 unless ($daysago);
my #months=qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
Localtime(time(86400*$daysago));
# YYYYMMDD, e.g. 20060126
return sprintf("%d%02d%02d",$year+1900,$mon+1,$mday);
}
my $deviationreportdate=getDate($daysbefore-1);
my $transactiondate=getDate($daysbefore);
my $filename="output.txt");
open(OUTPUTFILE,"> /tmp/$filename");
for my $Test_file (<Test_DDD*${deviationreportdate}*>)
{
if ($Test_file =~ /Test_DDD(\d+)/${deviationreportdate}*)
{
my $file = "DDD$1.txt";
my $ID="DDD$1";
open AIN, "<$file" or die($file);
open BIN, "<$Test_file" or die($Test_file);
my %seen;
}
This regular expression is invalid
$Test_file =~ /Test_DDD(\d+)/${deviationreportdate}*
you can only have modifiers after the last slash in a regex. I'm not exactly sure what you're trying to do with this, otherwise I would post the correct regex for you. maybe you ment this?
$Test_file =~ /Test_DDD(\d+)\/${deviationreportdate}*/
or this
$Test_file =~ /Test_DDD(\d+)${deviationreportdate}*/
I have the following conditional:
if ($self->path ne 'contact_us' && !grep { $status == $_ } 2, 3, 8) {
And it is throwing this warning:
Use of uninitialized value in numeric gt (>)
Of course, there's no numeric gt at all on the surface. $self->path is a Moose attribute accessor, so the only under-the-hood magic would be coming from that. But I can't see how that would be making a numeric gt comparison, especially since path is defined as follows:
has 'path' => (is => 'rw', isa => 'Str');
Any ideas on how this warning is getting thrown? I'm using Perl v5.8.8 built for i386-linux-thread-multi, if it matters in this case.
Update: Even more mysteriously, I've rewritten the conditional as follows:
my $cond1 = $self->path ne 'contact_us';
my $cond2 = !grep { $status == $_ } 2, 3, 8;
if ($cond1 && $cond2) {
And it's the third line that throws the warning. Carp::Always's stack trace isn't sufficiently informative. Some further disclosure, as I'm feeling utterly clueless now: The base file is a FastCGI script being called up by Apache's mod_fcgi.
Last update:
$status was getting set by a call to a method found in another module (My::Session). Here was line generating the warning in that module's method (note the errant >):
my $disputes => dbh('b')->selectrow_hashref($query);
What's confusing to me is why the warning didn't reference the module containing the offending line (it referenced the module making the method call, My::Page). Here's the full output from Carp::Always; there is an utter lack of mention of My::Session:
[Wed Feb 23 17:44:29 2011] [warn]
[client ---.---.94.159] mod_fcgid:
stderr: Use of uninitialized value in
numeric gt (>) at /path/to/My/Page.pm
line 65, referer:
https://testserver.domain.tld/help
[Wed Feb 23 17:44:29 2011] [warn]
[client ---.---.94.159] mod_fcgid:
stderr:
\tPage::BUILD('My::Page::Help=HASH(0xa7ce788)',
'HASH(0xa327904)') called at
/usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi/Class/MOP/Method.pm
line 123, referer:
https://testserver.domain.tld/help
[Wed Feb 23 17:44:29 2011] [warn]
[client ---.---.94.159] mod_fcgid:
stderr:
\tClass::MOP::Method::execute('Moose::Meta::Method=HASH(0x9fa357c)',
'My::Page::Help=HASH(0xa7ce788)',
'HASH(0xa327904)') called at
/usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi/Moose/Object.pm
line 57, referer:
https://testserver.domain.tld/help
[Wed Feb 23 17:44:29 2011] [warn]
[client ---.---.94.159] mod_fcgid:
stderr: \tMoose::Object::BUI, referer:
https://testserver.domain.tld/help
[Wed Feb 23 17:44:29 2011] [warn]
[client ---.---.94.159] mod_fcgid:
stderr:
LDALL('My::Page::Help=HASH(0xa7ce788)',
'HASH(0xa327904)') called at
/usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi/Moose/Meta/Class.pm
line 278, referer:
https://testserver.domain.tld/help
[Wed Feb 23 17:44:29 2011] [warn]
[client ---.---.94.159] mod_fcgid:
stderr:
\tMoose::Meta::Class::new_object('Class::MOP::Class::ANON::SERIAL::1=HASH(0xa3397c8)',
'HASH(0xa327904)') called at
/usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi/Moose/Object.pm
line 26, referer:
https://testserver.domain.tld/help
[Wed Feb 23 17:44:29 2011] [warn]
[client ---.---.94.159] mod_fcgid:
stderr:
\tMoose::Object::new('My::Page::Help',
'HASH(0xa339d38)') called at generated
method (unknown origin) line 3,
referer:
https://testserver.domain.tld/help
[Wed Feb 23 17:44:29 2011] [warn]
[client ---.---.94.159] mod_fcgid:
stderr:
\tMy::Page::new('My::Page::Suppo,
referer:
https://testserver.domain.tld/help
[Wed Feb 23 17:44:29 2011] [warn]
[client ---.---.94.159] mod_fcgid:
stderr: rt', 'HASH(0xa339d38)') called
at /path/to/My.pm line 44, referer:
https://testserver.domain.tld/help
[Wed Feb 23 17:44:29 2011] [warn]
[client ---.---.94.159] mod_fcgid:
stderr: \tMy::start() called at
index.fcgi line 9, referer:
https://testserver.domain.tld/help
My guess is that one of your arguments is an overloaded object, and that overloading is throwing the error. Check to see exactly what your arguments are:
print "$_: ", ref, $/ for $self, $self->path, $status;
Which should print something like:
HASH(0x12341234)=Self::Object: Self::Object
some/path:
4:
If instead you are getting:
HASH(0x12341234)=Self::Object: Self::Object
some/path: Some::Object
4: Some::Other::Object
Then you should look at each of those packages to see if there is overloading present.
You can also write a bool function which will force a value into a non-overloaded bool:
sub bool {$_[0] ? 1 : 0}
And then:
my $cond1 = bool $self->path ne 'contact_us';
my $cond2 = bool !grep { $status == $_ } 2, 3, 8;
if ($cond1 && $cond2) {
If that fixes the problem, chances are at least one of your arguments is an overloaded object that is misbehaving.
This also could possibly be caused by one of the autoboxing pragmas like use bigint; or use bignum; which convert literal numbers like 2, 3, 8 into overloaded objects. Are any pragmas like this in effect?
I'm pretty sure that you're not getting $status set properly somewhere above the code that you've pasted. You're probably also on an older version of Perl, since in ActiveState 5.12 on my MBP, it will print out the variable name which has failed, as it does in 5.10 under FreeBSD. Under 5.8.8 on my Linux-based VPS, the variable name isn't part of the fail message.
It would be easier to help with more than just a couple of lines of code, since usually the root cause of this sort of error isn't going to be found on the line where the program is dying, but due to a variable not really holding what you think it holds.