Re: Executing commands through Perl

2007-07-17 Thread Matthew Topper

-- Forwarded message --
From: Matthew Topper [EMAIL PROTECTED]
Date: Jul 17, 2007 6:17 AM
Subject: Re: Executing commands through Perl
To: Teresa Thomas [EMAIL PROTECTED]

It sounds like Perl might be overkill for this.  Personally, anytime I find
myself using the system call all the time, I seriously think about either
using a module, or just a simple bash script.  Although, Perl certainly can
do it with little trouble, if you just want to get it working.  In any
event, I really don't like the system call, or backticks for that matter.

On 7/16/07, Teresa Thomas [EMAIL PROTECTED] wrote:


Hi,

Its my first time (first day actually!) using Perl and I would like some
help in performing some relatively simple operations.

My program outputs two columns of text based data. I want to parse this
information, extract some contents and send the contents (which are
actually program names) to yum, to be installed into a Unix machine.

Currently, I'm extracting the names using split command and pushing
the program names into an array. I want to know how to call a command
line utility (like yum or rpm) through Perl. Does this require any
additional libraries?

Advice on any alternate/better way of achieving the same would be great!

Thanks,

Teresa

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/





Re: Parsing HTML (Table)

2007-07-17 Thread Rob Dixon

yitzle wrote:


I'm using WWW::Mechanize to retrieve a web page. I get to this line:

my $page = $mech-response()-decoded_content();

The page got a table with values I wish to extract. What module is 
best suited to getting to that data?


I'm hoping for a somewhat simple to use module. WWW::Mechanize is the
first object oriented module I used (this project), so I'm still 
getting used to it.


Hi. I recommend HTML::TableExtract for what you're describing. We can
help you more if you give us the URL of the web page you're looking at
and what data you need from it.

HTH,

Rob

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Fork()ing and CGI?

2007-07-17 Thread Ken Foskey
On Tue, 2007-07-17 at 00:44 -0400, yitzle wrote:
 I need some guidance...
 I'm thinking of writing a CGI script that someone can pass some data
 and set it running. The script may take a few seconds to run.
 Is it safe/correct/OK to have a CGI script fork, with one thread
 respondng with a HTTP response while the other thread does its work? I
 want the HTTP response to finish sending right away, and not have to
 wait for the script to finish.

I have done this and it works OK.

I used a second CGI that queried the log file stored on the server with
an auto-update flag.

Currently I am reading up on AJAX that seems to be the correct solution
to the problem and makes for some slick applications.

-- 
Ken Foskey
FOSS developer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Fork()ing and CGI?

2007-07-17 Thread Tom Phoenix

On 7/16/07, yitzle [EMAIL PROTECTED] wrote:


I'm thinking of writing a CGI script that someone can pass some data
and set it running. The script may take a few seconds to run.
Is it safe/correct/OK to have a CGI script fork, with one thread
respondng with a HTTP response while the other thread does its work?


Randal did something similar in this column:

   http://www.stonehenge.com/merlyn/WebTechniques/col20.html

In Randal's case, the user eventually gets a page saying that the
background process has finished its task. If your user won't want to
see the results, you could omit that part.

Cheers!

--Tom Phoenix
Stonehenge Perl Training

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: RegEx: matching ^ or with [^]?

2007-07-17 Thread Rob Dixon

yitzle wrote:


I know this isn't the best way to parse it, but I need to check the 
$ENV{'QUERY_STRING} for some values.


I originally had   =~ /^limit=([0-9]{1,3})$/   which worked. But I 
tried to replace the ^ with [^] and the $ with [$] to allow the 
string to be part of a longer string attached with an  on either 
side.


The point is, the [^] doesn't seem match either ^ or , like I want
to. Why is this? How do I match ^ or ? (I really should just split
on  and grep or whatever, but...)


After all the discussion, I suggest that all you really need is:

/\blimit=([0-9]+)\b/

Rob



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Fork()ing and CGI?

2007-07-17 Thread yitzle

Thanks for the replies!

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Executing commands through Perl

2007-07-17 Thread Teresa Thomas
Perl's system() function seems to be working great for simple commands 
like 'pwd' , 'ls' that does not require user interaction.  But when I 
try to execute commands that require user input (eg, su or yum while not 
on root), then it says 'standard in must be a tty' and fails.


Is this because Perl is not inheriting the standard input properly? Any 
ideas on how I can fix it?


Thanks in advance,

Teresa

Mr. Shawn H. Corey wrote:

Teresa Thomas wrote:

Hi,

Its my first time (first day actually!) using Perl and I would like 
some help in performing some relatively simple operations.


Welcome to the world of Perl.



My program outputs two columns of text based data. I want to parse 
this information, extract some contents and send the contents (which 
are actually program names) to yum, to be installed into a Unix machine.


You say outputs but you are trying to munge the data.  Data that is 
outputted cannot be munge.  You have to munge it before output.




Currently, I'm extracting the names using split command and pushing 
the program names into an array. I want to know how to call a command 
line utility (like yum or rpm) through Perl. Does this require any 
additional libraries?


Showing the piece of code that is giving you problems is a big help.  
I think it would be better if you created a script file that contains 
all the commands.  That way you can pre-view it.


But the command you want is system.  See `perldoc -f system`.



Advice on any alternate/better way of achieving the same would be great!

Thanks,

Teresa






--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




connect a database in remote server (can connect to the server via SSH)

2007-07-17 Thread zhangxiaoyu912
Hi, All:
I am a new to perl. My perl code need to connect to the database in
the remote server, and I can login that server via SSH. Can anyone
give me a hint about how can I do that? Many thanks.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Executing commands through Perl

2007-07-17 Thread Mr. Shawn H. Corey

Teresa Thomas wrote:
Perl's system() function seems to be working great for simple commands 
like 'pwd' , 'ls' that does not require user interaction.  But when I 
try to execute commands that require user input (eg, su or yum while not 
on root), then it says 'standard in must be a tty' and fails.


Is this because Perl is not inheriting the standard input properly? Any 
ideas on how I can fix it?


You can't run su except from a terminal.  This is not part of Perl, it's 
 part of the security for su.  There's no way around this.


If you want the program to access files not normally allowed by 
permissions, you set the program's owner to grant access and set its 
set-userid-on-execution bit (see `man chmod`).  The program then runs as 
it's owner userid rather than that of the person running it.



--
Just my 0.0002 million dollars worth,
   Shawn

For the things we have to learn before we can do them, we learn by 
doing them.

  Aristotle

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: connect a database in remote server (can connect to the server via SSH)

2007-07-17 Thread Tom Phoenix

On 7/17/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:


I am a new to perl. My perl code need to connect to the database in
the remote server, and I can login that server via SSH. Can anyone
give me a hint about how can I do that? Many thanks.


Have you seen what's on CPAN?

   http://search.cpan.org/search?query=sshmode=all

Good luck with it!

--Tom Phoenix
Stonehenge Perl Training

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Executing commands through Perl

2007-07-17 Thread Tom Phoenix

On 7/17/07, Teresa Thomas [EMAIL PROTECTED] wrote:


But when I
try to execute commands that require user input (eg, su or yum while not
on root), then it says 'standard in must be a tty' and fails.


These are programs that don't expect to be run by other programs, but
by humans. If you want to let the human at the keyboard control those
programs, you can run them that way by linking them to the terminal.
If you want your program to control the program as if your program
were the human, that's tougher.

But nobody wants to run su, just like nobody wants to go to the
airport; you only do it because it lets you do the thing you _really_
want to do. su is a program you use because you want to run a
different program (as a different user), right? You probably want to
use sudo to do the different program more directly; unlike su, sudo is
made to be run by other programs.

Good luck with it!

--Tom Phoenix
Stonehenge Perl Training

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: connect a database in remote server (can connect to the server via SSH)

2007-07-17 Thread Francisco Valladolid

Hi.

You must check if the Database ports are open, if no ask to the admin.

Regards

On 7/17/07, Tom Phoenix [EMAIL PROTECTED] wrote:


On 7/17/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

 I am a new to perl. My perl code need to connect to the database in
 the remote server, and I can login that server via SSH. Can anyone
 give me a hint about how can I do that? Many thanks.

Have you seen what's on CPAN?

http://search.cpan.org/search?query=sshmode=all

Good luck with it!

--Tom Phoenix
Stonehenge Perl Training

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/






--
Francisco Valladolid H.
-- http://bsdguy.net - Perl, [Open-Net] BSD fan. --


Re: Executing commands through Perl

2007-07-17 Thread John W. Krahn

Teresa Thomas wrote:
Perl's system() function seems to be working great for simple commands 
like 'pwd' , 'ls' that does not require user interaction.  But when I 
try to execute commands that require user input (eg, su or yum while not 
on root), then it says 'standard in must be a tty' and fails.


Is this because Perl is not inheriting the standard input properly? Any 
ideas on how I can fix it?


You probably need to use one of the modules IPC::Open2, IPC::Open3, IPC::Run 
or Expect.



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.-- Larry Wall

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: connect a database in remote server (can connect to the server via SSH)

2007-07-17 Thread Jeff Pang

--- [EMAIL PROTECTED] wrote:

 Hi, All:
 I am a new to perl. My perl code need to connect to
 the database in
 the remote server, and I can login that server via
 SSH. Can anyone
 give me a hint about how can I do that? Many thanks.
 

You may use perl's database operation module DBI.pm,if
you're doing database programming rather than db
administration.



 

Don't get soaked.  Take a quick peak at the forecast
with the Yahoo! Search weather shortcut.
http://tools.search.yahoo.com/shortcuts/#loc_weather

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: connect a database in remote server (can connect to the server via SSH)

2007-07-17 Thread Chas Owens

On 7/17/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

Hi, All:
I am a new to perl. My perl code need to connect to the database in
the remote server, and I can login that server via SSH. Can anyone
give me a hint about how can I do that? Many thanks.


To answer accurately we need some more information first:

1. What brand of database is it: Informix, Oracle, DB2, PostgreSQL,
MySQL, SQL Server, etc. (I assume it is an RDBMS rather than a flat
file or hierarchal database)?
2. Does the database only accept local connections? (do you you really
have to ssh to the box to connect to it?)
3. What OS is the client?
4. What OS is the server?
5. What control do you have over the remote machine?

In most cases you can simply install the DBI module and a DBD module
that corresponds to your RDBMS.  If some reason you can only connect
to the remote box through SSH you can still setup an ssh-tunnel and
connect to the RDBMS with the DBI that way.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Executing commands through Perl

2007-07-17 Thread Jeff Pang

--- Mr. Shawn H. Corey [EMAIL PROTECTED] wrote:
 You can't run su except from a terminal.  This is
 not part of Perl, it's 
   part of the security for su.  There's no way
 around this.
 

No way?I think Expect.pm can do this.Though putting
passwords, especially root passwords, into scripts in
clear text can mean security problems.


   

Get the Yahoo! toolbar and be alerted to new email wherever you're surfing.
http://new.toolbar.yahoo.com/toolbar/features/mail/index.php

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




HoH efficiency

2007-07-17 Thread Rodrick Brown

Is there a more efficient way to handle the method I choose to unroll my HoH.
Thanks.

#!/usr/bin/perl -w
use strict;
use warnings;
use Data::Dumper;

my @data = STDIN;

my ($user,$gid,$homedir,%userMap);
foreach(@data) {
 /^#/ and next;
 /(\w+):/ and $user = $1;
 /\w+:*:(\d+):/ and $gid = $1;
 /.*:(.*)$/ and $homedir = $1;
 $userMap{$homedir}-{$user} = $gid;
}

#print Dumper(\%userMap);

while(my ($k0,$h0) = each(%userMap)) {
 foreach my $shell ($k0) {
   print $shell,\n;
   print --\n;
   while(my ($k1,$v0) = each(%$h0)) {
 print $k1 $v0\n;
   }
   print \n;
 }
 #print $k,\n\t,$_,\n foreach(values %$v);
}


___DATA___FILE___
##
# User Database
#
# Note that this file is consulted when the system is running in single-user
# mode.  At other times this information is handled by one or more of:
# lookupd DirectoryServices
# By default, lookupd gets information from NetInfo, so this file will
# not be consulted unless you have changed lookupd's configuration.
# This file is used while in single user mode.
#
# To use this file for normal authentication, you may enable it with
# /Applications/Utilities/Directory Access.
##
nobody:*:-2:-2:Unprivileged User:/:/usr/bin/false
root:*:0:0:System Administrator:/var/root:/bin/sh
daemon:*:1:1:System Services:/var/root:/usr/bin/false
uucp:*:4:4:Unix to Unix Copy Protocol:/var/spool/uucp:/usr/sbin/uucico
lp:*:26:26:Printing Services:/var/spool/cups:/usr/bin/false
postfix:*:27:27:Postfix User:/var/spool/postfix:/usr/bin/false
www:*:70:70:World Wide Web Server:/Library/WebServer:/usr/bin/false
eppc:*:71:71:Apple Events User:/var/empty:/usr/bin/false
mysql:*:74:74:MySQL Server:/var/empty:/usr/bin/false
sshd:*:75:75:sshd Privilege separation:/var/empty:/usr/bin/false
qtss:*:76:76:QuickTime Streaming Server:/var/empty:/usr/bin/false
cyrusimap:*:77:6:Cyrus IMAP User:/var/imap:/usr/bin/false
mailman:*:78:78:Mailman user:/var/empty:/usr/bin/false
appserver:*:79:79:Application Server:/var/empty:/usr/bin/false
clamav:*:82:82:Clamav User:/var/virusmails:/bin/tcsh
amavisd:*:83:83:Amavisd User:/var/virusmails:/bin/tcsh
jabber:*:84:84:Jabber User:/var/empty:/usr/bin/false
xgridcontroller:*:85:85:Xgrid Controller:/var/xgrid/controller:/usr/bin/false
xgridagent:*:86:86:Xgrid Agent:/var/xgrid/agent:/usr/bin/false
appowner:*:87:87:Application Owner:/var/empty:/usr/bin/false
windowserver:*:88:88:WindowServer:/var/empty:/usr/bin/false
tokend:*:91:91:Token Daemon:/var/empty:/usr/bin/false
securityagent:*:92:92:SecurityAgent:/var/empty:/usr/bin/false
unknown:*:99:99:Unknown User:/var/empty:/usr/bin/false

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Writing a Program

2007-07-17 Thread CJ
To all you who know:

I'm trying to write a program, granted it's going to be a large one,
that will keep track of people's computers when they're in my shop
being repaired.  I want to assign a number to each computer system,
and that number will stay with that machine throughout the program.  I
want to be able to see when the computer is taken in, where it is at
the time, etc...

My question is this:

How would I go about writing this program in perl, and is perl the
language to write it in?  I'll use MySQL to store the data.  The
reason I chose perl is because I like linux, and perl runs excellently
in linux, and I'd like to do my developing on a linux box.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Writing a Program

2007-07-17 Thread yitzle

I'm not the most qualified to answer this question, but if all you
want is a simple menu driven interface for a MySQL DB, Perl should be
an easy way to accomplish it.
Using a graphical module you should also be able to make a nice GUI.

If you are going to go ahead, you want to first learn the basics of
Perl. You can get started at http://www.perl.org/
Once you are familiar with the language, take a look at
http://search.cpan.org/~capttofu/DBD-mysql-4.005/lib/DBD/mysql.pm
I think that's the commonly used library for MySQL.

HTH

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Q: cannot use 'use base' without quote ?

2007-07-17 Thread Jack Minoshima

Hi!
Nice to see you.
I'm new to OOP Peal.
Let me ask you a silly question.

When I try to use 'use base', I encountered an problem.
I wrote this program;

--- Animal.pm
package Animal;
sub speak {
my $class = shift;
print a $class goes , $class-sound, !\n;
}
sub AUTOLOAD {
my $class = shift;
print AUTOLOAD: a $class goes , $class-sound, !\n;
}
1;

--- Mouse.pm
use strict subs;
package Mouse;
use base 'Animal';
sub sound { 'squek' };
1;

--- farm.pl
use Mouse;
Mouse-speak;

and it work fine.

 C:\Documents and Settings\jackm\usetestfarm.pl
 a Mouse goes squek!

but when I unquote the quote of
use base 'Animal';
like this
 use base Animal;
It would cause an error;

C:\Documents and Settings\jackm\usetestfarm.pl
Unknown error
Compilation failed in require at C:\Documents and
Settings\jackm\usetest\farm.pl line 1.
BEGIN failed--compilation aborted at C:\Documents and
Settings\jackm\usetest\farm.pl line 1.

use Animal is allowed, but is use base Animal not allowed?
FYI, if you remove use strict subs, it won't be an error.

but in the file farm.pl,
use Mouse;
works but
use 'Mouse'

would be syntax error.

In summary ...
 no strict sub
  use Mouse OK
  use 'Mouse' NG
   use base Animal OK
  use base 'Animal' OK
use strict sub
  use Mouse OK
  use 'Mouse' NG
   use base Animal NG
  use base 'Animal' OK

Please tell my why I need quote after use base while using strict subs.
Thank you very much in advance !
-- jackm


Q: cannot use base while Exporting ?

2007-07-17 Thread Jack Minoshima

Hi.
Please allow me to ask another silly question.

I wrote the program and it works fine.


Animal.pm
package Animal;
use Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(speak);
sub speak {
print I speak!\n;
}
1;

--
Mouse.pm
package Mouse;
use Animal;
@ISA = qw(Animal);
@EXPORT = qw(speak sound);
sub sound {
print the sound!\n;
};
1;


farm.pl
use Mouse;
speak;
sound;

C:\Documents and Settings\jackm\usetestfarm.pl
I speak!
the sound!

but when I change Mouse.pm to replace use Animal and set @ISA with use
base, it won't work.
--
Mouse.pm
package Mouse;
use base qw(Animal);
@EXPORT = qw(speak sound);
sub sound {
print the sound!\n;
};
1;

C:\Documents and Settings\jackm\usetestfarm.pl
Can't call method sound on an undefined value at Animal.pm line 10.

Please someone kindly let me know why?
Thank you very much in advance.
I'm using;

C:\Documents and Settings\jackm\usetestperl -v


This is perl, v5.8.8 built for MSWin32-x86-multi-thread
(with 50 registered patches, see perl -V for more detail)

Copyright 1987-2006, Larry Wall

Binary build 820 [274739] provided by ActiveState
http://www.ActiveState.comhttp://www.activestate.com/
Built Jan 23 2007 15:57:46

Perl may be copied only under the terms of either the Artistic License or
the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using man perl or perldoc perl.  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

wirh Windows XP SP2.

Thank you !

-- jackm


Re: HoH efficiency

2007-07-17 Thread Jeff Pang

--- Rodrick Brown [EMAIL PROTECTED] wrote:

 Is there a more efficient way to handle the method I
 choose to unroll my HoH.
 Thanks.
 
 #!/usr/bin/perl -w
 use strict;
 use warnings;
 use Data::Dumper;
 
 my @data = STDIN;
 
 my ($user,$gid,$homedir,%userMap);
 foreach(@data) {
   /^#/ and next;
   /(\w+):/ and $user = $1;
   /\w+:*:(\d+):/ and $gid = $1;
   /.*:(.*)$/ and $homedir = $1;
   $userMap{$homedir}-{$user} = $gid;
 }
 
 #print Dumper(\%userMap);
 
 while(my ($k0,$h0) = each(%userMap)) {
   foreach my $shell ($k0) {
 print $shell,\n;
 print --\n;
 while(my ($k1,$v0) = each(%$h0)) {
   print $k1 $v0\n;
 }
 print \n;
   }
   #print $k,\n\t,$_,\n foreach(values %$v);
 }
 

Hello,

Just give my version.It does the same work and seems
more clear.

use strict;
use warnings;

my %hash;
open FD,'/etc/passwd' or die $!;
while(FD) {
chomp;
my ($user,$uid,$shell) = (split/:/)[0,2,6];
$shell ||= 'null';
push @{$hash{$shell}},[$user,$uid];
}
close FD;

for my $s (keys %hash) {
print \n$s\n\n;
for my $p (@{$hash{$s}}) {
print @$p\n;
}
}

__END__

HTH.


   

Moody friends. Drama queens. Your life? Nope! - their life, your story. Play 
Sims Stories at Yahoo! Games.
http://sims.yahoo.com/  

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Q: cannot use 'use base' without quote ?

2007-07-17 Thread Jack Minoshima

I forgot to describe my environment. it's here.

C:\Documents and Settings\jackm\usetestperl -v


This is perl, v5.8.8 built for MSWin32-x86-multi-thread
(with 50 registered patches, see perl -V for more detail)

Copyright 1987-2006, Larry Wall

Binary build 820 [274739] provided by ActiveState
http://www.ActiveState.comhttp://www.activestate.com/
Built Jan 23 2007 15:57:46

Perl may be copied only under the terms of either the Artistic License or
the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using man perl or perldoc perl.  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

wirh Windows XP SP2.

Thank you !

-- jackm

2007/7/18, Jack Minoshima [EMAIL PROTECTED]:


Hi!
Nice to see you.
I'm new to OOP Peal.
Let me ask you a silly question.

When I try to use 'use base', I encountered an problem.
I wrote this program;

--- 
Animal.pmhttp://animal.pm/
package Animal;
sub speak {
 my $class = shift;
 print a $class goes , $class-sound, !\n;
}
sub AUTOLOAD {
 my $class = shift;
 print AUTOLOAD: a $class goes , $class-sound, !\n;
}
1;

 --- 
Mouse.pmhttp://mouse.pm/
use strict subs;
package Mouse;
use base 'Animal';
sub sound { 'squek' };
1;

 --- farm.pl
use Mouse;
Mouse-speak;

and it work fine.

  C:\Documents and Settings\jackm\usetestfarm.pl
  a Mouse goes squek!

but when I unquote the quote of
 use base 'Animal';
like this
  use base Animal;
It would cause an error;

C:\Documents and Settings\jackm\usetestfarm.pl
Unknown error
Compilation failed in require at C:\Documents and
Settings\jackm\usetest\farm.pl line 1.
BEGIN failed--compilation aborted at C:\Documents and
Settings\jackm\usetest\farm.pl line 1.

use Animal is allowed, but is use base Animal not allowed?
FYI, if you remove use strict subs, it won't be an error.

 but in the file farm.pl,
 use Mouse;
works but
 use 'Mouse'

would be syntax error.

In summary ...
  no strict sub
   use Mouse OK
   use 'Mouse' NG
use base Animal OK
   use base 'Animal' OK
 use strict sub
   use Mouse OK
   use 'Mouse' NG
use base Animal NG
   use base 'Animal' OK

Please tell my why I need quote after use base while using strict subs.
Thank you very much in advance !
-- jackm



Re: Writing a Program

2007-07-17 Thread Daniel Kasak
On Wed, 2007-07-18 at 03:56 +, CJ wrote:

 To all you who know:
 
 I'm trying to write a program, granted it's going to be a large one,
 that will keep track of people's computers when they're in my shop
 being repaired.  I want to assign a number to each computer system,
 and that number will stay with that machine throughout the program.  I
 want to be able to see when the computer is taken in, where it is at
 the time, etc...
 
 My question is this:
 
 How would I go about writing this program in perl, and is perl the
 language to write it in?  I'll use MySQL to store the data.  The
 reason I chose perl is because I like linux, and perl runs excellently
 in linux, and I'd like to do my developing on a linux box.

You've made all the right decisions already :)

This sounds like an excellent use for my 'Axis' project:
http://entropy.homelinux.org/axis

You'll have to design your tables in MySQL. Then design your GUI with
Glade ( which designs Gtk2 interfaces ... Gtk2 is the widget toolkit
that gnome uses ). Then create some Gtk2::Ex::DBI and
Gtk2::Ex::Datasheet::DBI objects to connect your tables to your forms.
It's remarkably easy, requires *very* little code, and I'll help you out
if you get stuck.

--
Daniel Kasak
IT Developer
NUS Consulting Group
Level 5, 77 Pacific Highway
North Sydney, NSW, Australia 2060
T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
email: [EMAIL PROTECTED]
website: http://www.nusconsulting.com.au


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/