1833115 Members
3497 Online
110051 Solutions
New Discussion

perl module problem

 
SOLVED
Go to solution
Brian Bierman
Occasional Contributor

perl module problem

I am new to perl and I am struggling with the following in a perl module that I created.

$sql = <<'EOT';
select *
from tblCodeEventType
order by description
EOT

I am importing it into a perl script called test.pl using the following:
use storedProcs;

The entire script bombs when I import the module.
7 REPLIES 7
H.Merijn Brand (procura
Honored Contributor
Solution

Re: perl module problem

Good that you also attached it, because whitespace is the issue here. here-documents (the name of the << structure) expect the ending pattern on the start of the line. In your case it is not. Why not use q{} or qq{} instead?

package storedProcs;
BEGIN
{
use Exporter();
@ISA = qw(Exporter);
@EXPORT_OK = qw(&sp_EventType &sp_Test);
}
sub sp_EventType
{
#$sql = "Blah, blah, blah";
$sql = q{
select *
from tblCodeEventType
order by description
};
return $sql;
}
sub sp_Test
{
print "

It's aliiiiive!

";
}
END{}
1;


indent to your liking

Enjoy, have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Brian Bierman
Occasional Contributor

Re: perl module problem

That did it! Thanks for your help.
H.Merijn Brand (procura
Honored Contributor

Re: perl module problem

You're new here, so may I remind you of the screen you got when posting the question? If you forgot, please read http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x022718276953d61190040090279cd0f9,00.html

Enjoy, have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Brian Bierman
Occasional Contributor

Re: perl module problem

procura,

I have one more question. Can I include arguments passed to my sub within the q{} or qq{} contructs?

ie.

sub sp_EventType(arg1)
{
$sql = q
{
select * from tblCodeEventType where EventType = arg1
};

return $sql;
}

Once again, I am brand new to perl so please forgive my skewed syntax.
H.Merijn Brand (procura
Honored Contributor

Re: perl module problem

Sure you can :) q{} is like single quotes (hence the single q, and qq - you guessed - is the alternative way of using double quotes. The advantage of the q and qq structs is that you can use almost any delimiter to it, and thus can use the /real/ quotes inside q and qq.

so here's my favourite, using the semicolon :)

sub foo ($) # in perl5 you do not (yet) have named arguments
{ # if you want them, pass arguments in a hash
my $tbl = shift; # default arg to shift is @_ in
# sub's which represents the passed arguments
my $sql = qq;
select *
from $tbl
where field = 'blah';
return $sql;
} # foo

# in this case you don't need the $sql variable

and later

my $sql = foo ("clients");

If you're into database access, *please* take a look at the DBI module and the DBD::YourDatabase that fits it. It will make your life soooo much easier.

BTW I forgive your screwed syntax :) the ITRC molests neat indents and lined out spaces anyway, so posting self documenting code is nearly impossible :P

Enjoy, have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Brian Bierman
Occasional Contributor

Re: perl module problem

Thanks again. I am using the DBI module with MySql. I am used to SQL Server and am trying to compensate for MySql's lack of stored procedure and trigger capability. Not to mention the elimination of redundant code. Hence a module for sql statements and DB connects.

As you can imagine, this module can become quite large. I read that I can import just the subroutines that I need for a particular perl script and cut the overhead of loading the entire module. Is this correct?

H.Merijn Brand (procura
Honored Contributor

Re: perl module problem

Yes, correct.

Please do

# man perlmod

for the specifics. I'm not a module expert :)

Enjoy, have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn