Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

last hour of cb

by Tanktalus (Canon)
on Jan 26, 2007 at 20:59 UTC ( #596792=document: print w/ replies, xml ) Need Help??

Updates more-or-less every 5 minutes (except when there is no activity). Extracted from Tanktalus' CB Stats' database. Feedback
Shows the last hour or so, but never more than will fit in 64k, nor over two hours. Other sources of cb history
Last update: Jul 27, 2016 at 20:25 UTC

Previous message (not shown): Jul 27, 2016 at 18:36 UTC
[abisha]How to use a sub from another perl file which does not have a '.pl' or '.pm' extension. The file also has some a main routine besides the sub routines. I want to use just one function from that file in another perl file.
[abisha]Thanks for responding .Ya . That was what I thought too. But that other routine is just too long. I'm trying to make it work with 'use' or 'require' .
[abisha]I guess I'll resort to Copy/paste by EOD. coz i've worked on these for 2 days on no result. Thanks ww :)
[RonW]require 'filename.ext'; should work
[stevieb]abisha: it should work fine with require 'filename';. Then in the main script, just call the sub name as normal, as if it were in the local file
[stevieb]note that the script being required needs to return a true value at the end (eg: 1;)
[RonW]if you need the file included at compile time, use BEGIN { require 'filename.ext'; }
[abisha]Ya I tried that. But I get this error "Can't locate perf_check in @INC". To give more context, perf_check is the file. It has a subroutine along with a main routine. I want to use just the sub in another file
[abisha]When I used eval with require, I ran into another problem where it ran the whole file instead of taking just the sub
[abisha]thank RonW. But that too gave me the "Can't locate in INC" error
[stevieb]where is the file located? if it isn't in @INC, it won't be found. Note that (at least for a bit longer), @INC contains the cwd
[stevieb]try putting require '/full/path/to/filename'
[abisha]the file is located in the same directory as the calling file
[tye]so take $0, strip the end off of it and replace it with "perf_check", then do $file;
[tye]for example, using File::Spec::Functions
[abisha]Thanks stevieb , but when i tried that , that require statement starts running the whole program in that file.
[bart]Is '.' in @INC?
[tye]Note that '.' is the current working directory, which is often not the directory that the same as the directory the calling file is in.
[abisha]No '.' is not in @INC
[tye]well, of course it does. You can load a file of Perl code and say, just give me the subroutines, don't run the rest of the code. If you want to only reuse one subroutine, then you need to get that into a separate file.
[tye]er, "You *can't* ..."
[tye]so, stop trying to do some hackish nonsense and do the 5 minutes of work to make a real module in a *.pm file and use that module from both places that want that sub.

↑Previous Hour↑
↓Current Hour↓

[stevieb]I agree with tye. If you don't do this, in the future, you'll just repeat the same hackery instead of having a proper reusable module. Just extract all subs into a new pm file, then rewrite the original script to use that module
[abisha]yes you both are right. That would actually be much cleaner. Thank you all very much for your help
[SuicideJunkie]Note that the process can be as simple as dumping the sub{...} into a .pm file, slapping down a 1; at the end and saving it to perl\lib\
[tye]though, add a 'package' line and an @EXPORT_OK = is even better.
[tye](and 'use strict;', of course)
[abisha]I had tried that too tye but that didnt work either. Now i got permission to create a new *.pm and keep those sub there
[abisha]yep will do that SuicideJunkie
[talexb]talexb discovers that his Android phone has crashed again .. time to reboot! Ugh.

Log In?

What's my password?
Create A New User
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2016-07-27 21:20 GMT
Find Nodes?
    Voting Booth?
    What is your favorite alternate name for a (specific) keyboard key?

    Results (250 votes). Check out past polls.