CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
new perl function

 



stu7
Deleted

Jan 17, 2001, 10:56 AM

Post #1 of 2 (614 views)
new perl function Can't Post

sorry if this repeats... I asked this in #perl dalnet

In the shell, you can write new aliases easily, which will be active for any new shell script... how is
this done in perl ? Evidently there is no easy way, but would this be a good new function to write ?

Short of that, could someone show me how to write a new function replacement name into perl
to compile ?



japhy
Enthusiast / Moderator

Jan 17, 2001, 1:04 PM

Post #2 of 2 (605 views)
Re: new perl function [In reply to] Can't Post

You are talking about subroutines. Just create a file with all the "aliases" you want, and incorporate that into all the programs you want them in.


Code
# aliases.pm 

package aliases;

use strict;

my @export = qw( fopen cls );

sub import {
shift;
my $pkg = caller;
no 'strict';
*{"${pkg}::$_"} = \&$_ for @_ ? @_ : @export;
}

sub fopen {
my $file = shift;
local *FH;
open FH, $file or die "can't open $file: $!";
return \*FH;
}

{
my $cls = `clear`;
sub cls { print $cls }
}

1;

This module would be used like so:


Code
use aliases;  # imports fopen() and cls() 

use aliases qw( cls ); # imports ONLY cls()

Jeff "japhy" Pinyan -- accomplished hacker, teacher, lecturer, and author

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives