[25644] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7886 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 16 03:05:27 2005

Date: Wed, 16 Mar 2005 00:05:13 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 16 Mar 2005     Volume: 10 Number: 7886

Today's topics:
    Re: [Q]: How to sort first abc, then 123? <nospam-abuse@ilyaz.org>
    Re: Can this be more efficient? <tadmc@augustmail.com>
    Re: Can this be more efficient? <tim@vegeta.ath.cx>
    Re: DBI DBM Slow - Is a ramdisk the answer? <see.sig@rochester.rr.com>
    Re: DBI DBM Slow - Is a ramdisk the answer? <1usa@llenroc.ude.invalid>
    Re: DBI DBM Slow - Is a ramdisk the answer? <nospam@bigpond.com>
    Re: DBI DBM Slow - Is a ramdisk the answer? <pilkowsk@informatik.uni-marburg.de>
    Re: Extract data using Curl Unix Command & Perl Script  <ifiaz@hotmail.com>
    Re: Extract data using Curl Unix Command & Perl Script  <tadmc@augustmail.com>
        Free iPOD npicaut@clemson.edu
    Re: How to make a blessable anonymous scalar ref? <nospam-abuse@ilyaz.org>
        How to read buffered output from ping-like process <chris@devnull.org>
    Re: How to read buffered output from ping-like process <ccolumbu@hotmail.com>
    Re: printing to xls with Unicode encoding character <sam.wun@authtec.com>
    Re: Random String Generator <not@invalid.invalid>
    Re: Random String Generator <mark.clements@kcl.ac.uk>
    Re: regular expression help with apostrophe <see.sig@rochester.rr.com>
    Re: Win32: How to find out the number of serial ports? <josef.moellers@fujitsu-siemens.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 16 Mar 2005 07:35:33 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: [Q]: How to sort first abc, then 123?
Message-Id: <d18nk5$uog$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Fabian Pilkowski 
<pilkowsk@informatik.uni-marburg.de>], who wrote in article <MPG.1ca0b7c1ffa2ee999898d8@news.individual.de>:
> >   map {s/^~//; $_} sort map {s/^(?=[~\d])/~/; $_} @data;

> Sorry, but I can't get it out yet. If the unsorted @data is like
> 
>     my @data = qw( And64 And8 Nand64 Nand8 );
> 
> the desired output should be
> 
>     qw( And8 And64 Nand8 Nand64 );

This is not the problem in the Subject.  Since you want 8 before 64,
this is not easily made with substitutions followed by lexicographical
sort (unless you encode 64 as chr(64)).  So compexities associated
with conversion to arrays are hardly avoidable.

Yours,
Ilya

P.S.  I though you wanted 123 to be sorted after abc.


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

Date: Tue, 15 Mar 2005 17:09:04 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Can this be more efficient?
Message-Id: <slrnd3eqog.819.tadmc@magna.augustmail.com>

Ala Qumsieh <notvalid@email.com> wrote:
> Colin chaplin wrote:
> 
>> &opendir (".");
> 
> In general, it's not a good idea to use & when calling a subroutine. 
> This was necessary for Perl4 and before, but that is at least 10 years 
> old. Now, they are not needed, and using them has some side effects 
> which are described in perlsub.


Yes, but this happens to be the one case where using ampersand _is_
a good idea, namely when you have a collision between a user-defined
sub and a builtin and you want to call the user-defined one.


>>     &processFile($dir . "\\" . $name)
> 
> Perl allows you to use unix-style dir hierarchy delimiters, even on 
> Windows. 


It isn' Perl that is OK with forward slashes it is the Operating
System (apart from the command interpreter) that is OK with them.

You can use forward slashes on Windows even if you are not in
Perl (provided you are not in the command interpreter).


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Tue, 15 Mar 2005 23:31:39 GMT
From: Tim Hammerquist <tim@vegeta.ath.cx>
Subject: Re: Can this be more efficient?
Message-Id: <slrnd3erge.skt.tim@vegeta.saiyix>

Colin chaplin <Colin@chaplin.me.uk> wrote:
> I can't get that syntax to run from the command line, not sure why (NT
> platform "can't find string terminator ' before EOF") but if
> I understand the -ne switch it's effectively openinging every file,
> going through it line by line, which is pretty much what I'm doing
> now?

You code opens up each file, reads the entire file into an array, then
processes the array one element (line) at a time.

The -n (as well as -p) reads each successive line from the file on each
iteration of the loop.

You method of reading the file at once (also called "slurping") is often
faster because disk IO is done all at once.  However, there are times
when this backfires.  Very large files can take up too much memory when
slurped and force the OS to swap out memory to disk to make room.
Worse, if a file is large enough, it may have to be swapped out and
loaded in chunks, and you've lost any performance you might have gained.

Tips:

  - don't define functions with the same names as library functions,
    *especially* if you intend to use the original function within it.
    you're just asking for problems.
  - comment out the "processing" chunks of code for now to be sure the
    file open/read system is working and is not the bottleneck.
  - use strategically placed print() statements to provide status
    reports and find out where the bottleneck is occurring.
  - fall back to a readline algorithm (rather than slurping) unless
    you've otherwise determined that this is an unacceptable performance
    hit and can be improved via slurping.

HTH,
Tim Hammerquist


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

Date: Tue, 15 Mar 2005 23:25:17 GMT
From: Bob Walton <see.sig@rochester.rr.com>
Subject: Re: DBI DBM Slow - Is a ramdisk the answer?
Message-Id: <x9KZd.138182$nC5.89367@twister.nyroc.rr.com>

burlo.stumproot@gmail.com wrote:

> Using WinXP Activestate 5.8.4
> 
> I'm using dbi:DBM to analyze some data. I read it from a file,
> process it some and then put it in a dbi:DBM database. I run a couple
> of sql's on it and save the result for later use.
> 
> But I'm finding it rather slow. 18 sec(*) to do 126 inserts and I'm
> planning to do about 1000 inserts and then 5-10 selects when I'm
> working on live data.
> 
> I moved the database to a ramdisk(**) and it took about 1,4 seconds.
> (I'm not planning to save the database after each run.)
> 
> 
> But then I got to thinking, is this the best way? Perhaps it's
> possible to tell dbi:DBM not to write it's data to file, or at least
> delay writing until I have *a big* chunk of data or until I
> $dbh->disconnect;
 ...

> So my question is this:
> 
>  Can I speed up dbi:DBM without using a ramdisk?
>  If so how?
> 
>  Or should I use somthing other than DBI:DBM for this task?
 ...

Perhaps DBI with DBD::RAM would be helpful?  It should be able to 
do just what you indicate you want to do.

-- 
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl


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

Date: Tue, 15 Mar 2005 23:33:39 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: DBI DBM Slow - Is a ramdisk the answer?
Message-Id: <Xns961ABCD148C5Casu1cornelledu@127.0.0.1>

burlo.stumproot@gmail.com wrote in news:umzt4inpg.fsf@notvalid.se:

> 
> Using WinXP Activestate 5.8.4
> 
> I'm using dbi:DBM to analyze some data. I read it from a file,
> process it some and then put it in a dbi:DBM database. I run a couple
> of sql's on it and save the result for later use.
> 
> But I'm finding it rather slow. 18 sec(*) to do 126 inserts and I'm
> planning to do about 1000 inserts and then 5-10 selects when I'm
> working on live data.

Without sample code and data, it is very hard to make specific 
suggestions.

 ...

> But then I got to thinking, is this the best way? Perhaps it's
> possible to tell dbi:DBM not to write it's data to file, or at least
> delay writing until I have *a big* chunk of data or until I
> $dbh->disconnect;

Then you should turn AutoCommit off if you have it on. See 

http://search.cpan.org/~timb/DBI-1.48/DBI.pm#Transactions

> So my question is this:
> 
>  Can I speed up dbi:DBM without using a ramdisk?

I do not know.

>  Or should I use somthing other than DBI:DBM for this task?

I have been using SQLite a lot lately. I have not felt the need to 
benchmark anything because the performance (even in conjunction with 
Class::DBI) has been more than adequate for my needs. It also natively 
supports multiple tables with multiple columns in the database driver 
rather than the simple (key,value) tables of DBM.

The fact that you are using Storable for each row probably means a lot 
store/retrieve calls when you access columns.

> (**)
>     I'm currently using this, since I have an ancient app that
>     demands it's data from A:

I am confused. Is the database you are accessing with DBI DBD-DBM on the 
floppy disk? Then you have just found the bottleneck.

Even if you use SQLite, the floppy access speed will be the determining 
factor in how fast your application runs, and that ain't fast.

Sinan.


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

Date: Wed, 16 Mar 2005 11:03:43 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: DBI DBM Slow - Is a ramdisk the answer?
Message-Id: <39pevfF648juvU1@individual.net>

burlo.stumproot@gmail.com wrote:

> 
> Using WinXP Activestate 5.8.4
> 
> I'm using dbi:DBM to analyze some data. I read it from a file,
> process it some and then put it in a dbi:DBM database. I run a couple
> of sql's on it and save the result for later use.
> 
> But I'm finding it rather slow. 18 sec(*) to do 126 inserts and I'm
> planning to do about 1000 inserts and then 5-10 selects when I'm
> working on live data.

DBI isnt slow, your DBMS is.

Using indexes(primary key, secondary), integrity constraints (eg checking
existence of foreign keys),or insert triggers can slow inserts down.

gtoomey


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

Date: Wed, 16 Mar 2005 02:05:02 +0100
From: Fabian Pilkowski <pilkowsk@informatik.uni-marburg.de>
Subject: Re: DBI DBM Slow - Is a ramdisk the answer?
Message-Id: <MPG.1ca1a4ab83622e639898de@news.individual.de>

* Bob Walton wrote:
> burlo.stumproot@gmail.com wrote:
> > 
> > I moved the database to a ramdisk(**) and it took about 1,4 seconds.
> > (I'm not planning to save the database after each run.)
> > 
> > So my question is this:
> > 
> >  Can I speed up dbi:DBM without using a ramdisk?
> >  If so how?
> > 
> >  Or should I use somthing other than DBI:DBM for this task?
> 
> Perhaps DBI with DBD::RAM would be helpful?  It should be able to 
> do just what you indicate you want to do.

A few days ago I've read in comp.lang.perl.misc [1] that DBD::RAM isn't 
the most recent module for this (the latest version on CPAN is from May 
2000, nearly 5 years ago). Look at DBD::AnyData which docs contains a 
section named "Working with in-memory tables".

    http://search.cpan.org/~jzucker/DBD-AnyData-0.08/AnyData.pm

regards,
fabian

[1] Message-ID: <d043s8$g81$1@rzcomm2.rz.tu-bs.de>


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

Date: 15 Mar 2005 18:50:14 -0800
From: "ifiaz" <ifiaz@hotmail.com>
Subject: Re: Extract data using Curl Unix Command & Perl Script from Webpage
Message-Id: <1110941414.223783.247650@g14g2000cwa.googlegroups.com>

> > Thanks Tad,
>
>
> You are welcome, you can show your gratitude by composing followups
properly:
>
> Please do not top-post.
What does this mean?

>
> Please do not full-quote.
Does this mean I should delete unnecessary parts when I reply?

>
> Please do not quote .sigs.
What does this mean?

Could you explain a bit clearer as I do not get your meaning. I will
follow accordingly as I am relatively new to newsgroups.

> > I tried using your script for the latest results, and it works like
a
> > wonder:
>
>
> That is how ALL of _my_ code works!
>
> heh.
>
>
> [snip code fragments]
>
>
> > But, both your version of the script and my version stops after
> > processing approx. the 90th student number unconditionally although
the
> > loop extends beyond that.
>
>
> It gets all 318 of them when I try it.

Is it without any change in the code?

> > Could you or someone explain why?
>
> Nope, since I cannot duplicate the problem.
>
> (but I do see that 64 of the regno's return no results,
>  invalid registration numbers I assume...
> )

I assure you that it is not because of no results for some regnos.

But, yet after the 90th student number, the program stops indefinitely
and I have to click ctrl+c to break.

I am using Perl 5.8.5, Windows 98 SE, Cygwin. Any comment on this is
appreciated.



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

Date: Tue, 15 Mar 2005 22:35:25 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Extract data using Curl Unix Command & Perl Script from Webpage
Message-Id: <slrnd3fdsd.99h.tadmc@magna.augustmail.com>

ifiaz <ifiaz@hotmail.com> wrote:
>> > Thanks Tad,
>>
>>
>> You are welcome, you can show your gratitude by composing followups
> properly:
>>
>> Please do not top-post.
> What does this mean?


   http://www.catb.org/~esr/jargon/html/T/top-post.html


>> Please do not full-quote.
> Does this mean I should delete unnecessary parts when I reply?


Exactly right.


>> Please do not quote .sigs.
> What does this mean?


A ".sig" is the "signature" at the end of a post, after the
line with 2 hyphens and a space char on it.

You should snip those when replying, unless the .sig itself
is what youu are commenting on.


> I am relatively new to newsgroups.


Please see the Posting Guidelines for this newsgroup, and follow
the links it contains:

   http://mail.augustmail.com/~tadmc/clpmisc.shtml


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 15 Mar 2005 16:49:33 -0800
From: npicaut@clemson.edu
Subject: Free iPOD
Message-Id: <1110934173.467973.190790@o13g2000cwo.googlegroups.com>

Check out this great site that is giving away totally FREE iPods!

I've joined and I think you should as well.

It's a completely legitimate offer, and this company has already given
away $4 million in FREE stuff!

All you have to do is join, complete an online offer, and refer friends
to do the same. That's it!

Here is my referral link. To help me get my iPod, click this exact link
to join, or copy and paste it into a browser:
http://www.freeiPods.com/?r=15015872



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

Date: Wed, 16 Mar 2005 07:51:23 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: How to make a blessable anonymous scalar ref?
Message-Id: <d18ohr$urf$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Anno Siegel
<anno4000@lublin.zrz.tu-berlin.de>], who wrote in article <d17mpp$32f$1@mamenchi.zrz.TU-Berlin.DE>:
> > >   bless \undef,  'Foo'  ===> Modification of a read-only value attempted
> > >   bless \\undef, 'Foo'  ===> [ no error ]
> > >   bless \1,      'Foo'  ===> Modification of a read-only value attempted
> > >   bless \\1,     'Foo'  ===> Modification of a read-only value attempted

> > I don't know why they behave the precise way they do, but I can rationalize
> > why they don't behave the same way.  1 is a constant, while undef is
> > actually a function invokation, even thought it is often used as if it were
> > a constant.
> 
> Ah, but being a function doesn't prevent it from returning a read-only
> value, or an alias to one.  Constants (as in the pragma) do that, and
> so does
> 
>     sub const { return $_ for 3 }

a) I think you confuse functions vs subroutines (or whatever are the
   proper names for them: builtins and functions?).  [Actually, there
   is a third category, XSUBs, which is free to behave in yet another
   way - per author's whim...]

b) Theoretically, \VALUE should generate a reference to VALUE,
   moreover, it should be a reference to the CONTAINER which has VALUE
   at this moment.  Apparently, it does not: calling "$_" several
   times can produce different VALUES (depending on the current value
   of $_), but the CONTAINER should be the same (the so-called
   "target" SV allocated for temporary value of operator "").

c) A natural guess is that operator \ notices that its operand is a
   temporary container, and generates a copy before it creates the
   reference.  In other words, \"$_" behaves as

     \ do {my $tmp = "$_"}

This is too heavy magic; in this case its result is intuitive; in many
others it is probably not...

Hope this helps,
Ilya


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

Date: Tue, 15 Mar 2005 19:23:31 -0600
From: Chris <chris@devnull.org>
Subject: How to read buffered output from ping-like process
Message-Id: <iPLZd.30458$Q83.9693@bignews5.bellsouth.net>

I am trying to read some data from another process, let’s call the 
program foo (binary and I don’t have the source). It works like ping in 
that it spits output to the screen every few seconds and has to be 
killed with control-c. I can write a script to read data from ping and 
kill the ping after say 10 seconds. But I don’t get any data from foo 
even though it behaves just like ping at the command prompt. (I even 
tried sending the data to a file but data doesn’t show up until 4096 
bytes are written and that is too long to wait.) I’ve tried all kinds of 
things like setting the file desc to non-blocking, using sysread, and 
even fork (open FD, “-|”) with foo as the child, but still no luck. Any 
ideas are appreciated. What is the shell doing to get the buffered 
output from foo on a line-by-line basis? Here is what I have that works 
for ping (on linux).

Thanks, Chris

eval
{
     local $SIG{'ALRM'} = sub { die "alarm\n"; };
     alarm 10;
     unless(open(FD, "/bin/ping myhost |"))
     {
       die "Unable to open pipe\n";
     }
     while($line = <FD>)
     {
       print "$line";
     }
     unless(close(FD))
     {
       die "Unable to close pipe\n";
     }
     alarm 0;
};
local $SIG{'INT'} = 'IGNORE';
kill INT => -$$;


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

Date: Tue, 15 Mar 2005 17:53:16 -0800
From: "Chad Columbus" <ccolumbu@hotmail.com>
Subject: Re: How to read buffered output from ping-like process
Message-Id: <7mMZd.234144$0u.49225@fed1read04>

> eval
> {
>     local $SIG{'ALRM'} = sub { die "alarm\n"; };
>     alarm 10;
>     unless(open(FD, "/bin/ping myhost |"))
>     {
>       die "Unable to open pipe\n";
>     }
>     while($line = <FD>)
>     {
>       print "$line";
>     }
>     unless(close(FD))
>     {
>       die "Unable to close pipe\n";
>     }
>     alarm 0;
> };
> local $SIG{'INT'} = 'IGNORE';
> kill INT => -$$;

Chris,
This code printed the ping results on STDOUT, it never went to the file handle.
If that is the case for you, just redirect the STDOUT to a file or var 
temporarily. 



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

Date: Wed, 16 Mar 2005 10:51:46 +0800
From: sam <sam.wun@authtec.com>
Subject: Re: printing to xls with Unicode encoding character
Message-Id: <d188jl$16e6$2@news.hgc.com.hk>

sam wrote:

> jmcnamara@cpan.org wrote:
> 
>> The more recent versions of Spreadsheet::WriteExcel support utf8
>> transparently with Perl 5.8. For older versions of perl you can use
>> UTF-16.
>>
>> See this example of Chinese in Big5 format from the standard
>> Spreadsheet::WriteExcel distro:
>>
>> http://search.cpan.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.11/examples/unicode_big5.pl 
>>
>>
>> http://search.cpan.org/src/JMCNAMARA/Spreadsheet-WriteExcel-2.11/examples/unicode_big5.txt 
>>
>>
>> There are also several other encoding examples in the same distro.
>>
>> John.
>> -- 
>>
> Hi John, thank you very much for this info, this bit of coding is 
> aparently missing from my perl code.
> 
As I look thru the code, I found this is only for converting an external 
file to an excel file.
How can I take the result of the print statement from perl and convert 
the result to an excel file? the result of the print statement is 
chinese characters.

Thanks
Sam

> Thanks
> Sam


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

Date: Wed, 16 Mar 2005 11:23:41 +1000
From: Matthew Braid <not@invalid.invalid>
Subject: Re: Random String Generator
Message-Id: <d181qt$ikb$1@bunyip2.cc.uq.edu.au>

DMB wrote:
> I need to write a Perl function that returns a 32 character randomly
> generated string of characters.
> 
> I tried the following with success, but I thought someone out there
> might have a cleaner way to do this.
> 
> my @c = qw(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3
> 4 5 6 7 8 9);
> 
> my $ID = $c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand
> @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand
> @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand
> @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand
> @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand
> @c].$c[rand @c].$c[rand @c].$c[rand @c];
> 

If you don't mind only having hex characters (which helps* avoid 
unwanted and unexpected phrases popping up in your string...):

my $id = sprintf("%08X%08X%08X%08X",
                  rand(4294967295),
                  rand(4294967295),
                  rand(4294967295),
                  rand(4294967295));

Also limits the number of calls to rand, so should be faster.

MB

* Not a complete solution to that though


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

Date: Wed, 16 Mar 2005 07:30:40 +0100
From: Mark Clements <mark.clements@kcl.ac.uk>
Subject: Re: Random String Generator
Message-Id: <4237d28d$1@news.kcl.ac.uk>

DMB wrote:
> I need to write a Perl function that returns a 32 character randomly
> generated string of characters.
> 
> I tried the following with success, but I thought someone out there
> might have a cleaner way to do this.
> 
> my @c = qw(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3
> 4 5 6 7 8 9);
> 
> my $ID = $c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand
> @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand
> @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand
> @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand
> @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand @c].$c[rand
> @c].$c[rand @c].$c[rand @c].$c[rand @c];
> 
Other solutions to this have already been posted, *but* bear in mind 
that rand produces pseudo-random numbers that aren't suitable for use in 
eg cryptography. You may want to check out Crypt::Random (I used to use 
Math::TrulyRandom but it doesn't look like that is being actively 
maintained).

Mark


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

Date: Tue, 15 Mar 2005 23:17:40 GMT
From: Bob Walton <see.sig@rochester.rr.com>
Subject: Re: regular expression help with apostrophe
Message-Id: <o2KZd.94044$H05.31174@twister.nyroc.rr.com>

Fabian Pilkowski wrote:

> * Bob Walton wrote:
> 
 ...
>>    /(?:.*\\|^)[^']+$/
 ...
>>__END__
>>just a path\
> 
> 
> If your string could be "just'a'path\" then your code will say there is 
> "at least one apostrophe in filename" -- but it's just a path without a 
> filename ;-)
> 
> Hence, I'd change the latter »+« in your regex to »*«, so that it could 
> match on empty filenames too.
 ...
> fabian

Good catch.  Thanks.

-- 
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl


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

Date: Wed, 16 Mar 2005 08:45:10 +0100
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: Win32: How to find out the number of serial ports?
Message-Id: <d18o9q$ulh$1@nntp.fujitsu-siemens.com>

Thomas Kratz wrote:
> Josef Moellers wrote:

>> Now I'd like to add a feature to scan the serial ports for the device,=
=20
>> but rather than assume that any modern PC has 2 serial ports, I'd like=
=20
>> to determine exactly how many serial ports the current system supports=
=2E

> Here's a way using the WMI interface. I guess you could do the same by =

> going through the registry after resolving a bunch of cryptic=20
> device_ids, but this is a case where WMI actually saves time and nerves=
=2E
>=20
> use strict;
> use warnings;
>=20
> use Win32::OLE qw/in/;
>   Win32::OLE->Option(Warn =3D> 1);
>=20
> my $wmi =3D Win32::OLE->GetObject(
>    "winmgmts:{impersonationLevel=3Dimpersonate,(security)}"
> ) or die
>    "error initializing WMI interface, ",
>    Win32::OLE->LastError;
>=20
> print $_->{DeviceID}, "\n"
>    for in($wmi->InstancesOf('Win32_SerialPort'));

Thanks, "Tausend dank".

Josef
--=20
Josef M=F6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize
						-- T.  Pratchett



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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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 V10 Issue 7886
***************************************


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