Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple syntax question.

Status
Not open for further replies.

MissouriTiger

Programmer
Oct 10, 2000
185
US
Hi guys, happy holidays,

I'm interested in knowing if there might be a less redundant way to write the follwing type of function call in Perl (format_date is a user-defined function). It just seems a bit cumbersome to have to include the variable name twice. Is there an alternative way to write such a statement and achieve the same results?

$date = format_date($date);


******************************************************
* BONUS !! BONUS !! BONUS !! BONUS !! BONUS !! BONUS *
******************************************************
This part is just for fun. Have you ever written a Perl program which interacts directly with a Java program, or vice-versa? Is such a thing possible? Can it be done without learning a complex new paradigm? I'm fascinated with the idea of getting 2 programs, which were written in 2 different languages, to interact with each other.

Once again, happy holidays. I hope Santa is good to you all!

-Grega Claus _______________________________________
constructed from 100% recycled electrons
 
If the $date variable exists in a block that also includes the format_date() function, you should be able to modify $date directly within the function. All of the object lovers out there are cringing right now, though.

The OO way to do it would be to make an object that had a format_date() function in the object definition, then you could call $date->format_date().

****Bonus comment****

You could easily do this by communicating via sockets or a database. I think I've read something about JPerl. There's an article on this at DDJ (
Share and enjoy.
vrj
 
Thanks for the input vrj.

About my date function: The idea is that I have been writing a wide variety of generic functions to perform various tasks, validation, formatting, DB interaction, etc., and I call the functions when I need them. This makes my code extensible. The functions reside in different files than my program.

I just thought maybe there was an alternative syntax that I wasn't aware of.

As for objects in Perl, I'm not quite ready to start writing my own Perl objects, (although I do it in Java) and I'm not sure it would improve my app in any way. _______________________________________
constructed from 100% recycled electrons
 
Have something against passing by reference? Of course that means you have to dereference in the function.
Code:
my $stuff = 0;
print "stuff: $stuff\n";
&add_one(\$stuff);
print "stuff: $stuff\n";

sub add_one
{
    my $num = shift;
    $$num++ if(defined($num));
}
----------------------------------------------------------------------------------
...but I'm just a C man trying to see the light
 
Isn't it considered bad programming practice to pass data by reference? _______________________________________
constructed from 100% recycled electrons
 
Is it? I can't say I've had much instruction on good or bad practices. I figured since they put it in, might as well use it. Can anyone out there set me right? ----------------------------------------------------------------------------------
...but I'm just a C man trying to see the light
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top