using namespace

Is there anyway I can do a 
using namespace for a particular loop like in c++;
( for functions not exported )

FOr eg in a perl script 


use Some::Module
.....
{ 
  using namespace Some::Module;   # Is this possible ? 
  
  someFuntion1();          # Instead of Some::Module::someFunction1()
  someFunction2();         # Instead of Some::Module::someFunction2()
}

----------------------------------------

Thanks
Ram




0
ramprasad
1/27/2005 9:03:07 AM
perl.beginners 29388 articles. 4 followers. Follow

3 Replies
384 Views

Similar Articles

[PageSpeed] 46

see
perldoc -f import
perldoc -f use
and what happens when you
use Some::Module (qw/somefunction1 somefunction2/) ;

Manav


|-----Original Message-----
|From: Ramprasad A Padmanabhan [mailto:ramprasad.padmanabhan@oracle.com]
|Sent: Thursday, January 27, 2005 2:33 PM
|To: perl beginners
|Subject: using namespace
|
|
|Is there anyway I can do a 
|using namespace for a particular loop like in c++;
|( for functions not exported )
|
|FOr eg in a perl script 
|
|
|use Some::Module
|....
|{ 
|  using namespace Some::Module;   # Is this possible ? 
|  
|  someFuntion1();          # Instead of Some::Module::someFunction1()
|  someFunction2();         # Instead of Some::Module::someFunction2()
|}
|
|----------------------------------------
|
|Thanks
|Ram
|
|
|
|
|
|-- 
|To unsubscribe, e-mail: beginners-unsubscribe@perl.org
|For additional commands, e-mail: beginners-help@perl.org
|<http://learn.perl.org/> <http://learn.perl.org/first-response>
|
|

*********************************************************
Disclaimer:          

This message (including any attachments) contains 
confidential information intended for a specific 
individual and purpose, and is protected by law. 
If you are not the intended recipient, you should 
delete this message and are hereby notified that 
any disclosure, copying, or distribution of this
message, or the taking of any action based on it, 
is strictly prohibited.

*********************************************************
Visit us at http://www.mahindrabt.com

0
manavm
1/27/2005 9:16:29 AM
Hi Manav,
 But still import does not work across multiple files.

for eg, 
------------main.pl-------------
#!/usr/bin/perl
#
use Some::Module qw(someFunction1);
require MyLibModule;

# This function will now work
someFunction1();            

MyLibModule::someOtherFunction();

---------------END--------------------



--------------MyLibModule.pm--------------
#
#
#
sub someOtherFunction { 
   someFunction1() ; 
                        # WILL NOT WORK HERE 
                        # I have to write Some::Module::someFunction1()
}

1;
-----------------END----------------------------




Thanks
Ram


0
ramprasad
1/27/2005 9:24:51 AM
Ramprasad A Padmanabhan wrote:
> Is there anyway I can do a 
> using namespace for a particular loop like in c++;
> ( for functions not exported )

Below are a few dirty little tricks that can get you something similar, 
but I've never used them, and I'm not sure they are good practice...

Use at your own risk!

#!/usr/bin/perl

use strict;
use warnings;

use File::Spec ();

for my $o ( 'File::Spec' ) {
     print 'tmpdir: ' . $o->tmpdir(), "\n";
     print 'curdir: ' . $o->rel2abs( $o->curdir() ), "\n";
}

print '#' x 60, "\n";

do {
     print 'tmpdir: ' . $_->tmpdir(), "\n";
     print 'curdir: ' . $_->rel2abs( $_->curdir() ), "\n";
} for 'File::Spec';

print '#' x 60, "\n";

{
     local *tmpdir = sub { File::Spec->tmpdir(@_) };
     print 'tmpdir: ' . tmpdir(), "\n";
}

print '#' x 60, "\n";

use import 'File::Spec' => qw( tmpdir rel2abs curdir );

print 'tmpdir: ' . tmpdir(), "\n";
print 'curdir: ' . rel2abs( curdir() ), "\n";

__END__

And here is the 'import.pm' module used in the final example above:

package import;

sub import {
     my $caller = caller();
     my $package = shift;
     my $module  = shift;
     foreach my $meth ( @_ ) {
	*{"${caller}::${meth}"} = sub { $module->$meth( @_ ) };
     }
}

1;
0
ml
1/27/2005 10:49:20 AM
Reply:

Similar Artilces:

using a namespace in another namespace?
Is it possible to "use" a namespace in another namespace. Let's assume that I have Namespace1 (which has Class1 and Function1) and Namespace2 (which has Class2 and Function2). Now, I have both of these in seperate .cs files and I've compiled them by hand using the Command Prompt (I'm not using VS.NET). So, now I want to rewrite Namespace1 so that it "uses" Namespace2 (while still keeping it in a different .cs file) This is what I would want Namespace1 to look like.. namespace1.cs file namespace Namespace1 { // when I compile the file with this usi...

how do i use namespaces
what is the rule for namespaces? I wasn't aware that two .vb files could declare the same namespace and yet when I look at  ContactDb.vb and PortalCfg.vb they both declare the ASPNET.StarterKit.Portal namespace.  I thought when I tried this in the past that it caused some such Ambiguous namespace error when trying to compile. Another thing thats unclear to me is the fact that Configuration.vb doesn't declare any namespace, so what namespace needs to be imported in order to reference the classes in this file? 1)if you are using VS go to Project> Project Properties. ...

Using namespaces
Hi all, I have a noobish question;  I'm creating a data access layer in a separate file for my website.  When I try to use the namespace I get this error: Server Error in '/' Application. Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS0246: The type or namespace name 'DataAccessLayer' could not be found (are you missing a using directive or an assembly referen...

Using Using
I have just completed reading a chapter in my book on performance. The books says to speed up performance on your web site you should use the using statement when opening connections. My question is how do you catch errors if you are using this as apposed to a try catch block.thanksBryan  Why would you use it as an alternative to a try/catch statement. Couldn't you just do something like  public void UsingSomeMethod() { try { SomeMethod(); } catch(SomeException e) { /// do something useful }}public void SomeMethod() { using (Something) { ...

how to use your own namespace
I have created a namespace "DataControls" in which I have a class "DataCalender" But while I debug it ,shows an error "Could not load file or assembly 'DataCalender' or one of its dependencies. The system cannot find the file specified" in the second line where I have written "<%@ Register Namespace="DataControls" Assembly="DataCalender" TagPrefix="dc" %>" Is your class in DataCalendar assembly (DLL)? I think it's just a name of the class, but assembly name is different.My last project - .NET Tip of ...

When to use ( and when to use ((?
I'm just not getting it. When do you use ( in a statement, when do you need to use ((, and is the space after either or both mandatory? For example, I coded this statement: if (( $_ eq $bad_guys_ip )) { more_stuff_here }; Why the two (( in an if? And why does it seem to not work when I miss the space after the ((? Thanx! Mark me as... /Corn-fused|Dense/ > I'm just not getting it. >=20 > When do you use ( in a statement, when do you need to use ((, and is > the space after either or both mandatory? >=20 > For example, I coded this sta...

namespaces and using
Hi, When I create a class in a library I wrap everything in a namespace, like this in a header: namespace myLib { class someclass etc..... } If my custom class are using, say the list class from std, will there be any difference in writing {code} #include <list> using std::list; namespace myLib { class someclass using std::list ... } {/code} from putting the "using list"inside the namespace, i.e. {code} #include <list> namespace myLib { using std::list; class someclass using std::list ... } {/code} -totte With using std::list ...

Why can't global resource namespaces be used in an import namespace statement?
Custom namespaces for global resources within the Resources namespace is a completely undocumented but nice new feature: "~/App_GlobalResources/TransparentFolder/XXX.YYY.ZZZ.ResourceName.resx." This is an invariant file that gets code-generated into a public class ResourceName inside the namespace Resources.XXX.YYY.ZZZstring s= Resources.XXX.YYY.ZZZ.ResourceName.ResKey1; Before RTM I had a thousand entries which all appeared at once in the intellisense popup and were hard to navigate. Now I can break them up into different resx files and incorporate the namin...

what namespace do i need to "using" to use 'e.Item' ??
I'm trying to use (Label)e.Item.FindControl("Label1") - to get the text value of a label within a datalist for use in my code-behind, but my VS2005 will not allow me to use "Item" after "e." - I'm thinking it's because I'm missing a necessary namespace "USING" include at the top of the page. can anyone help?  The data type of "e" depends on the context and based on that it will have different properties.Can you post the event handler which has this "e" that you are trying to use?And lastly, you do not have to ...

Very basic que
My question is do we use some external tool for unit testing like NUnit or do we use System.Diagnostic namespace we have assertions built in the .NET like Debug.Assert so why do we need to use NUnit . can anybody explain me what all Debug.Assert can do and also I would also like to know what is  SqlTraceListener() can we user this to write to a log some errors. What are TraceListners in general? Thanks. Hi, Trace Listeners collect message and store them into an opropriate target, such as log, window, or text file. And it's also Testing for Performance Good luck!Please give ...

How to use the arguments to use() in the package being used
Howdy,=20 The subject says it all believe it or not :) What I'm trying to figure out is how to pass an argument=20 (pragma I believe is the proper term) to use() and do=20 sonethign in the package based on it. I've looked at CGI.pm source but can't seem to track it down.=20 (Similar idea as to CGIs -oldstyle_urls -newstyel_urls) http://search.cpan.org/~lds/CGI.pm-3.04/CGI.pm#PRAGMAS What I'd like to do is something like this: # for old time's sake we'll just use our favorite module use Foo::Monkey qw(:Foo :Bar -doamazingthings); #then in Foo::Monkey...

CS0246:The type or namespace name <type/namespace> could not be found (are you missing a using directive or an assembly reference?)
iam new to asp.net.i have created a class (invoice.cs), in the App_Code folder. Also a .dll file in the bin directory. i have used classes from both the dll and the class file to my .aspx and .aspx.cs pages. In the local server (using IDE), it's working. But in the case when i upload those files to the website, iam getting a error - CS0246 The type or namespace name <type/namespace> could not be found (are you missing a using directive or an assembly reference?). What's the problem. Please help. I read somewhere that it's something related to virtual directory.Is that corre...

Web resources about - using namespace - perl.beginners

Namespace - Wikipedia, the free encyclopedia
Namespaces provide a level of indirection to specific identifiers, thus making it possible to distinguish between identifiers with the same exact ...

Wikipedia:Help namespace - Wikipedia, the free encyclopedia
The Help namespace is a namespace consisting of Wikipedia pages whose titles begin with the prefix Help: , such as Help:Link . These pages contain ...

ICANN seeks to tackle DNS namespace collision risks
As the number of top-level domains undergoes explosive growth, the Internet Corporation for Assigned Names and Numbers (ICANN) is studying ways ...

OS X Lion: Guidelines for connecting to a DFS namespace via SMB
Ensure that the following guidelines are followed when connecting to a DFS namespace via SMB in OS X Lion.

Facebook's Namespace Land Grab? Or Maybe…It's Just Useful
Much buzz over the past few days about Facebook’s plans to let folks (and, ahem, brands) claim their namespaces on Facebook. IE, Starting this ...

Global Namespace for People (Part 3)
I ended yesterday’s post by saying that I would write about potential solutions to the global namespace problem for people (parts 1 and 2). So ...

Netflix namespace problem · Issue #34 · balloob/pychromecast · GitHub
pychromecast - Library for Python 2 and 3 to communicate with the Google Chromecast.

Adding Namespaces To Ruby
... about how close I can get Ruby to look like Clojure in size and style. Recently, what has bothered me most has been how you define a namespace ...

PHP 5.6 features built-in debugger, better namespace support
PHP, the venerable scripting language for server-side Web development, has been upgraded in a point release highlighted by a new debugger.

#include<bits/stdc++.h> using namespace std; int n, x, y; int main() { fo - Pastebin.com
PASTEBIN - #1 paste tool since 2002 create new paste tools api archive faq PASTEBIN create new paste trending pastes sign up login my alerts ...

Resources last updated: 1/9/2016 10:13:46 PM