LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 03-21-2008, 04:19 AM   #1
john83reuben
Member
 
Registered: Oct 2007
Location: Kuala Lumpur,Malaysia
Distribution: Debian Etch, OpenSuse
Posts: 129

Rep: Reputation: 17
need perl help...perl module problem


Guys, I am new to perl. I have a problem here.
This is my 1st script called Twiddle.pm

Code:
package Twiddle;

sub swap {
my $username = "john";    
}

1;
this is my second script

Code:
#!/usr/bin/perl
use strict;
use Twiddle;

print Twiddle::swap("my($username)");
print "\n";
when i execute, error comes. This is the error

Global symbol "$username" requires explicit package name at ./firstmodule.pl line 5.
Execution of ./firstmodule.pl aborted due to compilation errors.


how to solve this problem..
 
Old 03-21-2008, 07:07 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Location: the Netherlands
Distribution: lfs, debian, rhel
Posts: 7,514
Blog Entries: 1

Rep: Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140
Hi,

I don't think this print Twiddle::swap("my($username)"); is correct/will work.

The following will work:

my $username;
print Twiddle::swap($username);


Hope this helps.
 
Old 03-22-2008, 09:08 PM   #3
chrism01
Guru
 
Registered: Aug 2004
Location: Brisbane
Distribution: Centos 6.2, Centos 5.8
Posts: 11,740

Rep: Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905
Actually, you'd need to return $username from the pkg sub for the call to print it, otherwise it's just initialising it (in the sub).
You don't need to mention it in the .pl file, unless you are going to pass a new value in from there, in which case I'd declare/assign to it before calling the pkg sub, not inline, that's horrrible.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl module Compress::Zlib installed but perl not detecting it danran Programming 0 05-03-2007 01:50 PM
Perl datescript Issue, missing perl module? stefaandk Programming 5 02-19-2006 10:55 PM
Problem with perl module for w3c validator to work on my local Apache+PHP+perl instal tbamt Linux - Software 0 12-16-2004 05:37 PM
problem with perl module shdhnd Linux - Software 3 06-01-2004 04:16 PM
perl(Cwd) perl(File::Basename) perl(File::Copy) perl(strict)....What are those? Baldorg Linux - Software 1 11-09-2003 08:09 PM


All times are GMT -5. The time now is 02:36 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration