[16902] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4314 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 13 18:05:39 2000

Date: Wed, 13 Sep 2000 15:05:22 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <968882722-v9-i4314@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 13 Sep 2000     Volume: 9 Number: 4314

Today's topics:
    Re: @variable_list <tim@ipac.caltech.edu>
        [Newbie]File::Find question (Steve K. Brown)
        [Newbie]File::Find question (Steve K. Brown)
    Re: [Possibly OT] XS question regarding DBD::DB2 <dan@tuatha.sidhe.org>
        Analysing WinNT DNS cache <gjchap99@my-deja.com>
    Re: Analysing WinNT DNS cache <undergronk@my-deja.com>
    Re: Analysing WinNT DNS cache <undergronk@my-deja.com>
        Another Simple Question... <nightchills26@my-deja.com>
    Re: Another Simple Question... <newsposter@cthulhu.demon.nl>
    Re: Another Simple Question... (Jerome O'Neil)
        Can I call perl script from a  C process and have it pr <yanping@netilla.com>
    Re: Character Class in Regex - Despecify What? <tim@ipac.caltech.edu>
    Re: Eliminate Duplicates <bart.lateur@skynet.be>
    Re: Extra ^M in text file <iltzu@sci.invalid>
        Generating Random Password in Perl <garcia868@yahoo.com>
    Re: Generating Random Password in Perl (Randal L. Schwartz)
    Re: Getting started w/ Perl (Tim Hammerquist)
    Re: Getting started w/ Perl (Tim Hammerquist)
    Re: Getting started w/ Perl (Abigail)
        handling different 'use xxx' with unix/windows <wartski@pliantsystems.com>
    Re: handling different 'use xxx' with unix/windows <jeffp@crusoe.net>
    Re: handling different 'use xxx' with unix/windows (Brandon Metcalf)
    Re: handling different 'use xxx' with unix/windows (Jerome O'Neil)
    Re: help in writing a card game (Tony L. Svanstrom)
    Re: help in writing a card game <flavell@mail.cern.ch>
    Re: help in writing a card game <yanick@babyl.sympatico.ca>
    Re: help in writing a card game (John J. Trammell)
    Re: Help with scope and module <jeffp@crusoe.net>
    Re: Help with scope and module <tim@ipac.caltech.edu>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Wed, 13 Sep 2000 13:43:18 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: @variable_list
Message-Id: <39BFE6E6.F0FBBA40@ipac.caltech.edu>

Todd Anderson wrote:
> 
> Dear Sirs and or Madam,
> Thanks for your help. But it still isn't reading the lists. Any ideas?
> Thanks in advance for your help.

Are you sure $form_data{'state'} contains valid info? How 'bout throwing in some
debugging o/p to have a look? Is the letter case right? Is there a newline after
the state abbreviation? Come on, do some debugging! And if you're going to ask
us to debug for you a) be prepared to be ignored, b) give enough info for us to
work with, like a short test case (with input data) that shows your problem.

--

-- Tim Conrow         tim@ipac.caltech.edu                           |


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

Date: 13 Sep 2000 20:54:44 GMT
From: skbrown@vcd.hp.com (Steve K. Brown)
Subject: [Newbie]File::Find question
Message-Id: <8popik$7cf$1@news.vcd.hp.com>

I am trying to use File::Find to seach for files in a directory structure.  I am starting from a
directory and most of the subdirectories are two and three deep.  I have read and reread 
the File::Find instructions and can not find my answer there.  I have also tried reading 
the FAQ's and I have not been able to find an answer to my question.  So please help me!

There are 439 files to find.  They are in random order.
My code is as follows:

sub wanted{
   push @FileNames, $File::Find::name;
   chdir $vss;
}

for $i (values %Crc){
   chdir $vss;
   find(\&wanted, $i);
}

Where:
$vss is the starting directory
%Crc is the list of file names for which I want to find the path.

As you can see I am sending the find subroutine one file name at a time.  The problem 
is that only the first two files are found and then the rest can not be found.  The error
message reads:  "Can't stat FILENAME: No such file or directory" In the 
instructions when the find subroutine is called there is a chdir to the found 
directory.  Why is it that I can not chdir back to the source directory in between 
calls to the find subroutine?  What changes would you suggest to make my code work the
way I want it to work?

Steven K Brown
Hewlett-Packard
Vancouver Division


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

Date: 13 Sep 2000 21:20:29 GMT
From: skbrown@vcd.hp.com (Steve K. Brown)
Subject: [Newbie]File::Find question
Message-Id: <8por2t$7e2$1@news.vcd.hp.com>

My code is:

sub wanted{
   push @FileNames, $File::Find::name;
   print "\$File::Find::name:  $File::Find::name\n";
   print "\$j:  $j\n";
   chdir $vss;
}

for $i (values %Crc){
   chdir $vss;
   find(\&wanted, $i);
}

$vss is the orginal directory
%Crc is the list of file names

I have 439 files to find the path for.  They are in random order.  The File::Find instructions are
not clear to me.  I have tried the FAQ's and can not find the answer there either.  

I do know the Find does a chdir to the found directory.  This code finds the first two files and
then gives the error:  Can't stat FILENAME: No such file or directory.

Why is it that I can not chdir to the orginal directory in between find calls?
What changes do you suggest to make this code work better?

Steven K Brown
Hewlett-Packard
Vancouver Division



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

Date: Wed, 13 Sep 2000 19:41:24 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: [Possibly OT] XS question regarding DBD::DB2
Message-Id: <ELQv5.13340$CW2.149403@news1.rdc1.ct.home.com>

Ben Evans <bene@chiark.greenend.org.uk> wrote:

> The part I don't understand is the if (attribs) { ... } clause.
> I had taken the right-most assignment (attribs=Nullsv) in the
> function prototype (is that the right word for the 
> bind_param_inout(sth, param, value_ref, maxlen, attribs=Nullsv)
> line ?) to mean that attribs must have a Null scalar value.

Nope. That's setting a default if the parameter's not passed in by the
code using this function. If that parameter doesn't exist, then it's set
to Nullsv, which happens (conveniently) to be NULL. 

Basically the test is checking to see if something was passed, and use it
if it was.

					Dan


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

Date: Wed, 13 Sep 2000 20:10:24 GMT
From: Jack Altradmon <gjchap99@my-deja.com>
Subject: Analysing WinNT DNS cache
Message-Id: <8pomut$fc1$1@nnrp1.deja.com>

I'm running WinNT DNS for Internet connection. Looking at the cache,
you can see all internet resolutions. My boss now wants me to try and
analyse what sort of sites users have been visiting! Now, disregarding
the ethics of this, is it possible to use the Perl DNS modules to
extract this information or do I need to look at 3rd party software
solutions..

If Perl DNS can achieve this, how would I do it ?

Thanks...


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Wed, 13 Sep 2000 21:12:35 GMT
From: Scott Kirk <undergronk@my-deja.com>
Subject: Re: Analysing WinNT DNS cache
Message-Id: <8poqjf$k54$1@nnrp1.deja.com>

In article <8pomut$fc1$1@nnrp1.deja.com>,
  Jack Altradmon <gjchap99@my-deja.com> wrote:
> I'm running WinNT DNS for Internet connection. Looking at the cache,
> you can see all internet resolutions. My boss now wants me to try and
> analyse what sort of sites users have been visiting! Now, disregarding
> the ethics of this, is it possible to use the Perl DNS modules to
> extract this information or do I need to look at 3rd party software
> solutions..
>

Managers often think this kind of thing is a good idea, but the data
you get back will often be meaningless.  But, he's not going to be
convinced by anything you say, so he'll get you to do it anyway and
probably agree later that it was a waste of time ;-)

I guess what you are trying to do is look at a list of IP addresses in
a log file and find out what names those web sites have.  Right?

The first thing you need to do is get the DNS 'cache' into a format
your Perl script can read.

Then you need to read all about gethostbyaddr() which will do a reverse
DNS lookup and give you back the hostname.

perdoc perlfunc
perldoc -f gethostbyaddr

A lot of hosts on the Internet don't have a name, so you won't get an
answer, which brings me back to my original point.

Er, doesn't your firewall give you this information anyway?

HTH
--
Scott Kirk
My deja.com mailbox is full of spam. Use this instead:
perl -e '$_ = "znvygb: haqretebax\@lnubb.pbz";
tr/A-Za-z/N-ZA-Mn-za-m/; print;'


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Wed, 13 Sep 2000 21:23:18 GMT
From: Scott Kirk <undergronk@my-deja.com>
Subject: Re: Analysing WinNT DNS cache
Message-Id: <8por7d$ksq$1@nnrp1.deja.com>

Oops, fingr troble.  I also meant to say

The code you will needs looks somthing like this..

use Socket;
$host = gethostbyaddr inet_aton($ipadres), AF_INET;

And use Deja News excellent search engine to look in the archive for
previous posts on gethostbyaddr

HTH
--
Scott


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Wed, 13 Sep 2000 18:29:50 GMT
From: Night Chills <nightchills26@my-deja.com>
Subject: Another Simple Question...
Message-Id: <8poh21$7n4$1@nnrp1.deja.com>

Hi Again!
  Okay this question should be a snap for all you seasoned Perl pro's
out there (and probably to the newbies too) but it certainly has me
stumped (an easy task apparantly).  Here is the question:

  I am wanting to access a network resource from a Java applet. Now,
before you wig out I am not asking about the Java part of it because I
already have that figured out. My question is: can a perl script access
ANY network resource that is available to the scripts owner account?
For instance, if I wanted the script to start Telnet and shuffle info
back and forth between the applet and the telnet program sitting on the
server could it do that?

See, I told you it was simple.....

Anthony


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 13 Sep 2000 18:47:36 GMT
From: Erik van Roode <newsposter@cthulhu.demon.nl>
Subject: Re: Another Simple Question...
Message-Id: <8poi48$m1u$1@internal-news.uu.net>

Night Chills <nightchills26@my-deja.com> wrote:

> My question is: can a perl script access
> ANY network resource that is available to the scripts owner account?
> For instance, if I wanted the script to start Telnet and shuffle info
> back and forth between the applet and the telnet program sitting on the
> server could it do that?

  The Net::Telnet module perhaps?

Erik



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

Date: Wed, 13 Sep 2000 18:53:27 GMT
From: jerome@activeindexing.com (Jerome O'Neil)
Subject: Re: Another Simple Question...
Message-Id: <H2Qv5.159$L46.202442@news.uswest.net>

Night Chills <nightchills26@my-deja.com> elucidates:

> My question is: can a perl script access ANY network resource that 
> is available to the scripts owner account?

Generaly, yes.

> For instance, if I wanted the script to start Telnet and shuffle info
> back and forth between the applet and the telnet program sitting on the
> server could it do that?

Yes.  You could do it in a number of ways, depending on what you mean
by "start Telnet."

See:: IO::Socket and Net::Telnet for more specifics.

HTH!


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

Date: Wed, 13 Sep 2000 20:48:45 GMT
From: "ypw" <yanping@netilla.com>
Subject: Can I call perl script from a  C process and have it process C data structure?
Message-Id: <NKRv5.598$JT3.29834@newsread2.prod.itd.earthlink.net>

hi, everyone,

My question is that:

Can I activate a Perl script from a process written in C and have
 a complex C data structure passed into it so that the Perl script
can retrieve all the info from the structure and send them to a
remote web server using WDDX?

I am wondering if I should use perlembed, perlguts and perlcall
to do this. Your suggestions will be greatly appreciated.

Thanks,

Yanping





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

Date: Wed, 13 Sep 2000 14:51:11 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: Character Class in Regex - Despecify What?
Message-Id: <39BFF6CF.4CD74569@ipac.caltech.edu>

Elisa Roselli wrote:
> 
> I've set myself the exercise of creating a simple Perl program that would
> extract the lines of any given character in a play, together with the
> leading cue. In the input file, the characters' names appear in all caps,
> followed by a tab, followed by their lines; two new lines separate the
> chunks.
> 
> LYSANDER  Why should he stay, whom love doth press to go?
> 
> HERMIA  What love could press Lysander from my side?
> 
> LYSANDER  Lysander's love, that would not let him bide,
>   Fair Helena, who more engilds the night
>   Than all you fiery oes and eyes of light.
>   Why seek'st thou me? could not this make thee know,
>   The hate I bear thee made me leave thee so?

As Sean said, paragraph mode is the way to go. But he didn't address getting the
cue line. I just know there's a cooler way to do this, but I'd probably do
something like (untested) ...

my $play = shift @ARGV;
my $character = uc shift @ARGV;
open(PLAY,$play) or die "$!";
$/ = "";
my @lines = <PLAY>;
for my $linenum (grep $lines[$_]=~/^$character\t/,0..$#lines) {
  print ($linenum>0?$lines[$linenum-1]:"")."\n\n$lines[$linenum]\n\n";
}

This won't work if a character can have multiple paragraphs under his name.
Extension to this case is left as an exercise.

[Didn't TomC post a challenge some time ago for how to match a pattern and print
it out with selectable context? What ever came of that?]

--

-- Tim Conrow         tim@ipac.caltech.edu                           |


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

Date: Wed, 13 Sep 2000 21:15:34 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Eliminate Duplicates
Message-Id: <m8rvrs4ukvlfekjr63fukd27dnajmp8gg8@4ax.com>

Iain Chalmers wrote:

>>             |     A hash! I should be using a hash for this! |

>"in", "unique", "duplicate" - yes, but "first"??? _really_???

	$hash{$_} ||= keys %hash;

There. %hash contains unique values, with as a value an index for the
order in which it first appeared. You can use it to sort the keys into
the order of first appearance.

If you want "last" instead of "first", use "=" instead of "||=":

	$hash{$_} = keys %hash;

Also note that the index number is different in both cases. With an
empty hash:

	$hash{a} ||= keys %hash;
	print $hash{a};
-->
	1

	$hash{a} = keys %hash;
	print $hash{a};
-->
	0

So in the ||= case, the hash entry is created before the RHS is
evaluated, in the = case, after.

-- 
	Bart.


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

Date: 13 Sep 2000 21:37:37 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Extra ^M in text file
Message-Id: <968880881.19167@itz.pp.sci.fi>

In article <39B36DA7.9E233657@nortel-dasa.de>, Levy, Joshua wrote:
>
>If when u transfer from unix/linux to NT you tar the files, the ^M won't
>appear, it only affects text files, tar & Zip will be spared.

This isn't even wrong.  You may have had a coherent thought in your
head when posting, but it was obviously lost in the transmission.

-- 
Ilmari Karonen - http://www.sci.fi/~iltzu/
Please ignore Godzilla  | "By promoting postconditions to
and its pseudonyms -    |  preconditions, algorithms become
do not feed the troll.  |  remarkably simple."  -- Abigail



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

Date: Wed, 13 Sep 2000 13:07:48 -0700 (PDT)
From: J Garcia <garcia868@yahoo.com>
Subject: Generating Random Password in Perl
Message-Id: <20000913200748.749.qmail@web1607.mail.yahoo.com>

I am looking for any tips or any pre-written Perl code
on how to generate random passwords for users wishing
to register. Any help on how to do that? Thanks.

__________________________________________________
Do You Yahoo!?
Yahoo! Mail - Free email you can access from anywhere!
http://mail.yahoo.com/


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

Date: 13 Sep 2000 13:33:53 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Generating Random Password in Perl
Message-Id: <m1aedcghfy.fsf@halfdome.holdit.com>

>>>>> "J" == J Garcia <garcia868@yahoo.com> writes:

J> I am looking for any tips or any pre-written Perl code
J> on how to generate random passwords for users wishing
J> to register. Any help on how to do that? Thanks.

Are you looking for a model of a registration system?  If so,
check out columns #5, #49, and #50 at

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

There's stuff in there about generating basic passwords as well, or
even sidestepping the issue by simply providing a token to verify the
user's own password.

If you're looking for "pronouncable passwords", check out the
CPAN module Crypt::RandPasswd.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Wed, 13 Sep 2000 18:04:36 GMT
From: tim@degree.ath.cx (Tim Hammerquist)
Subject: Re: Getting started w/ Perl
Message-Id: <slrn8rvh5h.lv.tim@degree.ath.cx>

Logan Shaw <logan@cs.utexas.edu> wrote:
> I will caution, though, that as much as I love Perl, it may not be the
> best first language to learn.  Computer science programs at
> universities spend lots of times drilling into your head all the
> programming mistakes you can make in the beginning that will cause you
> heartache later and how to avoid them, and one of the tools they use
> for this is teaching languages.  Those languages aren't necessarily
> useful in the real world, but they get you into good habits, and that
> *is* useful.  So, if you're learning with Perl, just realize that it
> gives you lots of freedom, and probably only experts know enough to
> exercise all that freedom.

I really do appreciate that teaching languages drill home certain
points.  I was intrigued that ABC, also a teaching language written by
the creator of Python (and an ancestor of Python) was the origin
of Python's indentation-based statement grouping.

Perl is a fine language for beginners.  And so is Java.  Though they are
often at opposite end of the spectrum as languages go, programming
languages fit your personality and mood much like music.  Each language,
of course, has its strengths and weaknesses.  My advice is, for each
project, select the language appropriate.

New languages are numerous and eminent.  Don't be afraid to learn them.
And you may always have a favorite, but don't just neglect other languages.
The industry at large may not _always_ share your taste.  =)

</Rant>

-- 
-Tim Hammerquist <timmy@cpan.org>

I haven't failed, I've found 10,000 ways that don't work.
	-- Thomas Edison


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

Date: Wed, 13 Sep 2000 18:11:10 GMT
From: tim@degree.ath.cx (Tim Hammerquist)
Subject: Re: Getting started w/ Perl
Message-Id: <slrn8rvhhr.lv.tim@degree.ath.cx>

Chris Stith <mischief@motion.net> wrote:
> I would disagree that it's the absolute worst to use as a beginning
> language. I think COBOL, Fortran, RPG, Forth, or JCL would be much worse as
> a first language. Some people might say that C or C++ is worse as a first
> language too.

I actually think C/C++ would be a good first language.  It's not the
most forgiving language, but it discourages the rampant idea that anyone
with a computer and internet connection can be a professional
programmer.  C/C++ forces you to pay attention to details that (IMHHHO)
even a Perl or Visual Basic programmer should keep in the back of their
minds.

> I played with AtariBasic when I was young. I started
> in school with *gasp* Borland's Turbo Pascal and Microsoft's QBASIC, since
> that's what my high school taught. At least QBASIC has subroutines and
> doesn't need line numbers for every line. I taught myself a little bit of C
> and some x86 assembly, but not a lot. I then went to uni, where the CS
> program was taught mostly around Ada.

<OT>

Frighteningly similar to my progression!  TRS-80 BASIC -> Turbo C++ ->
MS QuickBasic (not QBasic) -> 80x86 Assembly -> Visual Basic -> more C++
-> JavaScript -> Java -> Perl -> Python.   No Ada though.

-- 
-Tim Hammerquist <timmy@cpan.org>
If the human mind was simple enough to understand,
we'd be too simple to understand it.
	-- Emerson Pugh


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

Date: 13 Sep 2000 19:56:13 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Getting started w/ Perl
Message-Id: <slrn8rvmss.ku0.abigail@alexandra.foad.org>

Tim Hammerquist (tim@degree.ath.cx) wrote on MMDLXX September MCMXCIII in
<URL:news:slrn8rvhhr.lv.tim@degree.ath.cx>:
@@ 
@@ Frighteningly similar to my progression!  TRS-80 BASIC -> Turbo C++ ->
@@ MS QuickBasic (not QBasic) -> 80x86 Assembly -> Visual Basic -> more C++
@@ -> JavaScript -> Java -> Perl -> Python.   No Ada though.


I've to wonder about such linear progressions. Mine is more (time going
vertically, with the present downwards)


ed/vi   Awk  sh                     .-------Pascal           68k      *roff 1984
  |  \   |  / |           .-Modula-II       / |               |         X   1985
  |   |  |  | |          /     X           /  | Simula67      |             1986
  |   |  |  | |         /            Modpas   |    X          |   LaTeX     1987
  |   |  |  | |        /               X      |      Miranda 6810   |       1988
  |   |  |  | |       /                       |         X     X     |       1989
  |   |  |  | |  .-C /                        |                     |       1990
  |   |  |  | +-' LPC                         |                     |       1991
 vile |  | / /|   /|                          |                     |       1992
  |    \ |/ /.+--' |                          X                     |       1993
  |     \||// |    |                                                |    
  |     Perl  |    |                                                |       1995
  |      |    |    |         Javascript           SQL               |       1996
  |      |    |    |             X                 |                |    
  |      |    |    |                               |      Java      |       1998
  |      |    |    |                               |        X       |  pic  1999
  V      V    V    V                               V                V   V   2000




Abigail
-- 
map{${+chr}=chr}map{$_=>$_^ord$"}$=+$]..3*$=/2;        
print "$J$u$s$t $a$n$o$t$h$e$r $P$e$r$l $H$a$c$k$e$r\n";


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

Date: Wed, 13 Sep 2000 13:58:14 -0400
From: Mark Wartski <wartski@pliantsystems.com>
Subject: handling different 'use xxx' with unix/windows
Message-Id: <39BFC035.C642EF0D@pliantsystems.com>

This is a multi-part message in MIME format.
--------------4D4450F5CC71C564AD508DBE
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

I have a situation where I want to use Device:SerialPort for unix and
use Win32::SerialPort for win32.
How do I conditionally use one or the the other depending on the OS?

I have tried conditionally using them using the ^O with no luck
(preprocessed ...).

Any ideas are welcome.

Mark

--------------4D4450F5CC71C564AD508DBE
Content-Type: text/x-vcard; charset=us-ascii;
 name="wartski.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Mark Wartski
Content-Disposition: attachment;
 filename="wartski.vcf"

begin:vcard 
n:Wartski;Mark
x-mozilla-html:TRUE
org:Pliant Systems Inc.
adr:;;;;;;
version:2.1
email;internet:wartski@pliantsystems.com
title:Principal Engineer
x-mozilla-cpt:;0
fn:Mark Wartski
end:vcard

--------------4D4450F5CC71C564AD508DBE--



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

Date: Wed, 13 Sep 2000 15:34:07 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: handling different 'use xxx' with unix/windows
Message-Id: <Pine.GSO.4.21.0009131532390.23599-100000@crusoe.crusoe.net>

[posted & mailed]

On Sep 13, Mark Wartski said:

>I have a situation where I want to use Device:SerialPort for unix and
>use Win32::SerialPort for win32.
>How do I conditionally use one or the the other depending on the OS?

Use a BEGIN block:

  BEGIN {
    if ($^O =~ /win/i) {
      require Win32::SerialPort;
      Win32::SerialPort->import;
    }
    else {
      require Device::SerialPort;
      Device::SerialPort->import;
    }
  }

The BEGIN block makes the require+import happen at compile time, just like
use would.

-- 
Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/



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

Date: 13 Sep 2000 19:50:29 GMT
From: bmetcalf@nortelnetworks.com (Brandon Metcalf)
Subject: Re: handling different 'use xxx' with unix/windows
Message-Id: <8polq5$n66$1@bcrkh13.ca.nortel.com>

wartski@pliantsystems.com writes:

 > I have a situation where I want to use Device:SerialPort for unix and
 > use Win32::SerialPort for win32.
 > How do I conditionally use one or the the other depending on the OS?
 > 
 > I have tried conditionally using them using the ^O with no luck
 > (preprocessed ...).

if ($^O =~ /win/i) {
   use Win32::SerialPort
} else {
   use Device::SerialPort
}


Brandon


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

Date: Wed, 13 Sep 2000 20:17:55 GMT
From: jerome@activeindexing.com (Jerome O'Neil)
Subject: Re: handling different 'use xxx' with unix/windows
Message-Id: <ThRv5.198$L46.236433@news.uswest.net>

bmetcalf@nortelnetworks.com (Brandon Metcalf) elucidates:
> wartski@pliantsystems.com writes:

> > I have tried conditionally using them using the ^O with no luck
> > (preprocessed ...).
> 
> if ($^O =~ /win/i) {
>    use Win32::SerialPort
> } else {
>    use Device::SerialPort
> }

As use is a compile time directive, this isn't going to work for you.  For 
runtime use, you would need "require" and the varous packages import methods.


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

Date: Wed, 13 Sep 2000 20:16:11 +0200
From: tony@svanstrom.com (Tony L. Svanstrom)
Subject: Re: help in writing a card game
Message-Id: <1egwywh.pi8l3e10343bkN%tony@svanstrom.com>

Yanick Champoux <yanick@babyl.sympatico.ca> wrote:

> Kelley Kent <kelley.a.kent@intel.com> wrote:

> : My code, and heck even my logic, are probably la crappy
> : as the French might say.
> 
>       Eh. I doubt we may say that. 'Amas improbable d'horribles 
>       circonvolutions psychotropiques', on the other hand... ;)

But you're not French, you're to the French like the "Americans" are to
the English...


     /Tony... anyone here that I didn't manage to insult this time? ;-)
-- 
     /\___/\ Who would you like to read your messages today? /\___/\
     \_@ @_/  Protect your privacy:  <http://www.pgpi.com/>  \_@ @_/
 --oOO-(_)-OOo---------------------------------------------oOO-(_)-OOo--
   on the verge of frenzy - i think my mask of sanity is about to slip
 ---ôôô---ôôô-----------------------------------------------ôôô---ôôô---
    \O/   \O/  ©99-00 <http://www.svanstrom.com/?ref=news>  \O/   \O/


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

Date: Wed, 13 Sep 2000 20:47:25 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: help in writing a card game
Message-Id: <Pine.GHP.4.21.0009132044030.12665-100000@hpplus03.cern.ch>

On Wed, 13 Sep 2000, Tony L. Svanstrom wrote:

> But you're not French, you're to the French like the "Americans" are to
> the English...

A French colleague once told me firmly: "in matters of the French 
language, never tangle with a Quebecois".

(Not that I had any intentions of doing so, then or since!)



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

Date: Wed, 13 Sep 2000 19:12:23 GMT
From: Yanick Champoux <yanick@babyl.sympatico.ca>
Subject: Re: help in writing a card game
Message-Id: <rkQv5.11866$Kp4.410720@news20.bellglobal.com>

Tony L. Svanstrom <tony@svanstrom.com> wrote:
: Yanick Champoux <yanick@babyl.sympatico.ca> wrote:

:> Kelley Kent <kelley.a.kent@intel.com> wrote:

:> : My code, and heck even my logic, are probably la crappy
:> : as the French might say.
:> 
:>       Eh. I doubt we may say that. 'Amas improbable d'horribles 
:>       circonvolutions psychotropiques', on the other hand... ;)

: But you're not French, you're to the French like the "Americans" are to
: the English...

	Are you sure you tested your code?

	package FRENCH;
	# ...
	package FRENCH::CANADIAN;
	@ISA = qw/ FRENCH OTHER_STUFF_WE_PROBABLY_SHOULDNT_MENTION_HERE /;
	# ...

	$yanick = new FRENCH::CANADIAN;
	print "Ventre bleu!" if $yanick->isa( 'FRENCH' );

	:)

:      /Tony... anyone here that I didn't manage to insult this time? ;-)

	Depends. Is there any Dogon folks around? :)

Joy,
Yanick

-- 
eval" use 'that poor Yanick' ";
print map{ (sort keys %{{ map({$_=>1}split'',$@) }})[hex] }
qw/8 b 15 1 9 10 11 15 c b 13 1 12 b 13 f 1 c 9 a e b 13 0/;


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

Date: 13 Sep 2000 19:20:17 GMT
From: trammell@nitz.hep.umn.edu (John J. Trammell)
Subject: Re: help in writing a card game
Message-Id: <slrn8ruqil.cec.trammell@nitz.hep.umn.edu>

On Wed, 13 Sep 2000 08:42:31 -0700, Kelley Kent <kelley.a.kent@intel.com> wrote:
>Thanx for all the input so far. Appears the consensus
>was that I was over-complicating things, as ever.

[snick!]

>My code, and heck even my logic, are probably la crappy
>as the French might say.  But again, this is just a sideline
>"project" that's purely for fun and in the interest of learning.

Absolutely.  Play and have fun with it.  It's a good way to learn.

Here's an idea for streamlining your deck representation: use numbers
0..51 to indicate your deck, then use '%' and '/' to calculate suit
and rank for each card.

  $suit = (qw[c d h s])[$card / 13];
  $rank = $card % 13;

-- 
John J. Trammell
johntrammell@yahoo.com


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

Date: Wed, 13 Sep 2000 15:32:33 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: Help with scope and module
Message-Id: <Pine.GSO.4.21.0009131531220.23599-100000@crusoe.crusoe.net>

[posted & mailed]

On Sep 13, Phil Barone said:

>What I would like to know if/how I can create a global variable in the
>main program accessable to the subroutines in my library?
>
>How/If it is possible for a subroutine in my library can access a
>subroutine in my main program?

Fully qualify it as $main::variable or main::function().

>sub s1 {
>  print "S1: $DEBUG\n";
>  &main1;
>}

This needs to be $main::DEBUG (or just $::DEBUG) and &main::main1 (or just
&::main1).

-- 
Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/



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

Date: Wed, 13 Sep 2000 14:27:04 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: Help with scope and module
Message-Id: <39BFF128.7E4AC61F@ipac.caltech.edu>

Phil Barone wrote:
> 
> Hi All,
>   I have a main program and a module that contains some library
> subroutines.
> 
> What I would like to know if/how I can create a global variable in the
> main program accessable to the subroutines in my library?
> 
> and
> 
> How/If it is possible for a subroutine in my library can access a
> subroutine in my main program?

Read perlmod. It goes into more than you asked, but it's good reading.

# Main
our $foo = 1; 
# Or, prior to 5.6 
# use vars qw($foo);
# $foo = 1;
sub printit { print @_,"\n"; }

package Bar;
main::printit($main::a);

--

-- Tim Conrow         tim@ipac.caltech.edu                           |


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V9 Issue 4314
**************************************


home help back first fref pref prev next nref lref last post