Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl function knowing receiver type

Tags:

function

perl

I have a text file, and a function to retrieve from that text file:

@thefile = read_file( 'somepathfile' );

I would like to have a different implementation of the read_file function depending on which type is receiving the information.

So if I write:

%thefile = read_file( 'somepathfile' );

then a different function will be executed.

How do I do that?

like image 650
john-jones Avatar asked Sep 06 '26 12:09

john-jones


1 Answers

While draegtun's answer illustrates a nice technique, I am going to recommend clarity. For example:

@thefile = read_file_lines( 'somepathfile' );

%thefile = read_file_pairs( 'somepathfile' );
like image 173
Sinan Ünür Avatar answered Sep 08 '26 17:09

Sinan Ünür



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!