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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Advanced:
new perl function



Jan 17, 2001, 10:56 AM

Post #1 of 2 (1701 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 ?

Enthusiast / Moderator

Jan 17, 2001, 1:04 PM

Post #2 of 2 (1692 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.


package aliases;

use strict;

my @export = qw( fopen cls );

sub import {
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 }


This module would be used like so:

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