PDA

View Full Version : Any PERL guys out there?




digital1
Nov 7, 2005, 11:09 AM
I am working on this project. This is my first major jump into PERL. I learned some PERL on my own, but this particular use of PERL is different for me. I am getting an error on this line in particular. It says its a bareword error. Does anyone know how I could fix this?


foreach $_ (@paws_output) {
if (/*Your Campus ID and/or Pin is invalid.*/) {
&print_cgi_error('Invalid Student ID/PIN number');
exit;
}


I get the error at the boldened line above. Any help is appreciated.



robbieduncan
Nov 7, 2005, 11:20 AM
You don't have any if conditions?

Edit:
Actually the above might be true but you are also using C styles comments Perl comments start with a # and continue to end of line.

digital1
Nov 7, 2005, 11:37 AM
Ok Robbie I changed the code to this:

foreach $_ (@paws_output) {
if (/.*Your Campus ID and/or Pin is invalid.*/) {
&print_cgi_error('Invalid Student ID/PIN number');
exit;
}



and I get this error:

Bareword found where operator expected at add_user_create.pl line 67, near "/.*Your Campus ID and/or"
(Missing operator before r?)
syntax error at add_user_create.pl line 67, near "/.*Your Campus ID and/or Pin "


Thats for more clearification. Before I was getting a different and longer error, but I compared it with the code that came from before. I assumed it was correct to put a search term in the if statement like that. Do you know of a better way to do this? Thanks :)

satans_banjo
Nov 7, 2005, 11:45 AM
i'm not really 'the man' for perl, but i think you need single quotation marks on that print (print 'whatever') because you're using slashes in that and slashes tend to initiate an escape command if you include them inside double speech marks (print "whatever")

hope thats right. i'll give it a whizz in terminal and see

EDIT: i was actually talking out of my arse. don't listen to anything i say from now on

khammack
Nov 7, 2005, 12:10 PM
if (/.*Your Campus ID and/or Pin is invalid.*/) {

You terminated the regular expression prematurely. Try this:

if (/.*Your Campus ID and\/or Pin is invalid.*/) {

-kev

khammack
Nov 7, 2005, 12:12 PM
Oh yeah, and the .* is redundant. This is cleaner:

if (/Your Campus ID and\/or Pin is invalid/) {

Those .* would only be necessary if you had anchors for the beginning (^) and end ($) of a line as part of the expression:

if (/^.*Your Campus ID and\/or Pin is invalid.*$/) {

But now it's all kinds of redundant. If you don't specifically need to match the end or beginning of a line, don't.

-kev

digital1
Nov 7, 2005, 04:31 PM
Thank you very much guys! I really appreciate the helpful responses and suggestions :) ;) One more quick problem... I am having trouble getting this line to execute correctly. No matter what this statement always executes as if the file doesn't exist and I know its there. Any ideas?

my @paws_output = `/cgi-bin/addu/automate_paws.ept $student_id $pin_no \'$semester\'`;
if (@paws_output < 1) {
&print_cgi_error('PAWS is unavailable, please try again later.');
exit;
}

khammack
Nov 7, 2005, 06:20 PM
Thank you very much guys! I really appreciate the helpful responses and suggestions :) ;) One more quick problem... I am having trouble getting this line to execute correctly. No matter what this statement always executes as if the file doesn't exist and I know its there. Any ideas?


By inspection nothing leaps out as syntactically incorrect, but you are packing a lot into a small amount of code. That is one of perl's strengths, but can also be one of it's weaknesses.

I'd propose busting it apart a bit.

my $cmd = "/cgi-bin/addu/automate_paws.ept $student_id $pin_no \'$semester\'";
print $cmd; # debug statement
my @paws_output = `$cmd`
print @paws_output; # debug statement
if (@paws_output < 1) {
&print_cgi_error('PAWS is unavailable, please try again later.');
exit;
}

Then, manually run the $cmd contents and see if they do the same thing as they do in your program.

-kev