Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

digital1

macrumors 6502
Original poster
Jan 2, 2002
294
0
Wisconsin
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

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
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

macrumors 6502
Original poster
Jan 2, 2002
294
0
Wisconsin
What about this?

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

macrumors regular
Sep 12, 2005
218
0
SE London
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

macrumors regular
Sep 28, 2004
166
0
Portland, OR
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

macrumors regular
Sep 28, 2004
166
0
Portland, OR
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

macrumors 6502
Original poster
Jan 2, 2002
294
0
Wisconsin
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

macrumors regular
Sep 28, 2004
166
0
Portland, OR
digital1 said:
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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.