[24365] in Perl-Users-Digest
Perl-Users Digest, Issue: 6554 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 11 18:06:18 2004
Date: Tue, 11 May 2004 15:05:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 11 May 2004 Volume: 10 Number: 6554
Today's topics:
Re: History of "statement if condition" syntax? <sbryce@scottbryce.com>
How to find the SSL certificate's expiration. (perlnovice)
Re: Making array elements Unique ctcgag@hotmail.com
Re: Newbie LWP question - simulate browser? (philthym)
preferences file (Jack)
Re: preferences file <uri@stemsystems.com>
Re: Printing multiple Array as multiple column (Jamie)
Re: Printing multiple Array as multiple column <remorse@partners.org>
Re: Printing multiple Array as multiple column (Anno Siegel)
Re: rapid development web interface to a database <pkent77tea@yahoo.com.tea>
Re: read from comma delimited file <dwall@fastmail.fm>
RegExp in one statement <dev_mail@donstefani.com>
Regular Expression Help? - Newbie Question <vikr@mindspring.com.invalid>
Re: Regular Expression Help? - Newbie Question <ittyspam@yahoo.com>
Re: Regular Expression Help? - Newbie Question <vikr@mindspring.com.invalid>
Re: Regular Expression Help? - Newbie Question <tadmc@augustmail.com>
Re: Regular Expression Help? - Newbie Question <ittyspam@yahoo.com>
Re: Searching CPAN by regexps <thepoet_nospam@arcor.de>
Re: Using match variables ($1, $2 ...) as variables. <gnari@simnet.is>
Re: Using match variables ($1, $2 ...) as variables. <uri@stemsystems.com>
Re: Using match variables ($1, $2 ...) as variables. <parimi@none.nowhere.com>
Re: Using match variables ($1, $2 ...) as variables. <parimi@none.nowhere.com>
Re: Using match variables ($1, $2 ...) as variables. <parimi@none.nowhere.com>
Win32::GetOSVersion - A Better Way? <>
Re: Win32::GetOSVersion - A Better Way? (Kevin Collins)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 11 May 2004 09:58:30 -0600
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: History of "statement if condition" syntax?
Message-Id: <10a1u0l66lbct3a@corp.supernews.com>
Roy Smith wrote:
> Perl is the only language I know of where you can invert the body and
> test of a condition, i.e. "exit 1 if $error'" instead of "if ($error) {
> exit 1};". What's the history behind that? Are there other languages
> which let you write conditionals like that? Did Perl invent that, or
> borrow it from some earlier language?
In 1976 I was writing that kind of syntax in BASIC+ V6B under RSTS-11 on
a PDP-11/70. There were also Unless and For modifiers. There may have
been an Until modifier, but I don't remember.
------------------------------
Date: 11 May 2004 12:16:46 -0700
From: tdang1@slb.com (perlnovice)
Subject: How to find the SSL certificate's expiration.
Message-Id: <8c66c403.0405111116.5b8a0686@posting.google.com>
Hello all,
I would like to write a script running on a client to determine the
expiration date of a web server's SSL certificate. But I do not know
how to. Can anybody give me a hint.
Thanks in advance for your information.
Tuan
------------------------------
Date: 11 May 2004 15:23:30 GMT
From: ctcgag@hotmail.com
Subject: Re: Making array elements Unique
Message-Id: <20040511112330.554$k5@newsreader.com>
"George Kinley" <georgekinley@hotmail.com> wrote:
> Hi
>
> I have an array of duplicate elements "char", I want to make the elements
> Unique and throw the redundant
> what solution came to my mind is I take element by element out of an
> array and create a hash checking the elements with "exists" and populate
> the hash is there any more intelligent way to do
Yes. Use a hash slice to populate the hash in one fell swoop.
Or better yet, don't make an array in the first place and use the hash
throughout.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 11 May 2004 13:33:57 -0700
From: philthym@yahoo.com (philthym)
Subject: Re: Newbie LWP question - simulate browser?
Message-Id: <3c7692f6.0405111233.5a0d1957@posting.google.com>
Sherm Pendley <spamtrap@dot-app.org> wrote in message news:<leqdnZLo8-B9agPdRVn-tw@adelphia.com>...
> philthym wrote:
>
> > I'm not sure I understand the whole lwp/get thing! What I'm wondering
> > is does this request effectively initiate the web server to return all
> > objects or just the HTML itself?
>
> It does *exactly* what you ask it to, no more - it fetches index.html.
> Parsing the HTML, extracting the <img ...> elements from it, and making
> additional requests to the server to fetch the images they point to, will
> require additional code.
>
> Have a look at HTML::Parser - it's a good place to start.
>
> sherm--
Thanks Sherm, I thought it would be something like that. I'll check out HTML:Parser.
Regards
Phil
------------------------------
Date: 11 May 2004 08:10:34 -0700
From: vomaringo@yahoo.com (Jack)
Subject: preferences file
Message-Id: <682ae665.0405110710.349b317d@posting.google.com>
hello,
have you a good way to examine a preferences file
with entries like this :
pref1=short
pref2=100
pref3=/tmp/file
thanks.
Regards,
------------------------------
Date: Tue, 11 May 2004 15:25:22 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: preferences file
Message-Id: <x7ekprkmu5.fsf@mail.sysarch.com>
>>>>> "J" == Jack <vomaringo@yahoo.com> writes:
J> have you a good way to examine a preferences file
J> with entries like this :
J> pref1=short
J> pref2=100
J> pref3=/tmp/file
use File::Slurp ;
my $pref_text = read_file( 'preferences' ) ;
my %prefs = $pref_text =~ m/^(\w+)=(.+)/gm ;
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: 11 May 2004 12:59:24 -0700
From: jnunner@hotmail.com (Jamie)
Subject: Re: Printing multiple Array as multiple column
Message-Id: <dc2a9475.0405111159.60bbab31@posting.google.com>
I had to do something fairly similar to that...except my results were
being formatted with html tags...
@array1 = (ab, bc, cd, ...)
@array2 = (cc, dd, ee, ...)
foreach $element1(@array1) {
$element2 = shift(@array2);
print qq($element1 $element2);
}
...this should work as long as the arrays are the same length.
------------------------------
Date: Tue, 11 May 2004 16:16:55 -0400
From: Richard Morse <remorse@partners.org>
Subject: Re: Printing multiple Array as multiple column
Message-Id: <remorse-059A7C.16165511052004@plato.harvard.edu>
In article <dc2a9475.0405111159.60bbab31@posting.google.com>,
jnunner@hotmail.com (Jamie) wrote:
> I had to do something fairly similar to that...except my results were
> being formatted with html tags...
>
> @array1 = (ab, bc, cd, ...)
> @array2 = (cc, dd, ee, ...)
>
> foreach $element1(@array1) {
> $element2 = shift(@array2);
> print qq($element1 $element2);
> }
>
>
> ...this should work as long as the arrays are the same length.
In the interest of TIMTOWTDI:
#!/usr/bin/perl
use strict;
use warnings;
my @a1 = qw/aa bb cc dd/;
my @a2 = qw/ee ff gg hh/;
while (@a1 || @a2) {
print shift(@a1) . ' ' . shift(@a2) . "\n";
}
__END__
If you don't want to get ugly warnings when one of the arrays is shorter
than the other, you can do 'no warnings qw/uninitialized/;'.
Note that this is a destructive procedure -- if you want your arrays
unscathed at the end, you were better not to use shift.
HTH,
Ricky
--
Pukku
------------------------------
Date: 11 May 2004 20:44:38 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Printing multiple Array as multiple column
Message-Id: <c7rdvm$3sg$1@mamenchi.zrz.TU-Berlin.DE>
Tore Aursand <tore@aursand.no> wrote in comp.lang.perl.misc:
> On Tue, 11 May 2004 22:18:56 +0000, Edward Wijaya wrote:
> > I have again this array:
> >
> > @array1 = (ab, bc, cd, ...)
> > @array2 = (cc, dd, ee, ...)
> >
> > with: print join("\n", @array), "\n";
> > it does give:
> >
> > ab
> > bc
> > cd
> >
> > Can we extend it to for multiple array?
>
> No need to; Text::Table alread does it for us.
Only part of it, really. Text::Table is line-oriented, but we are given
columns. There is no simple way to add whole columns to a table, so the
transposition problem that is being discussed in the other branch of the
thread remains.
The best Text::Table can do is:
my $tb = Text::Table->new( '', ''); # two title-less columns
$tb->add( $array1[ $_], $array2[ $_]) for 0 .. $#array1;
print $tb;
but the alignment problem this solves is non-existent with the given
data. 'print "$array1[ $_] $array2[ $_]\n"' would print the same.
Anno
------------------------------
Date: Tue, 11 May 2004 22:11:24 +0100
From: pkent <pkent77tea@yahoo.com.tea>
Subject: Re: rapid development web interface to a database
Message-Id: <pkent77tea-23B23B.22112411052004@pth-usenet-01.plus.net>
In article <bigiain-AD10DD.19563310052004@news.fu-berlin.de>,
Iain Chalmers <bigiain@mightymedia.com.au> wrote:
> In article <8c526b62.0405091341.784cdea5@posting.google.com>,
> carloschoenberg@yahoo.com wrote:
> > I am looking for the easiest web interface to a database. By easiest,
> > I mean most rapid development. Because the requirements are so simple
> > and standard, I'm hoping that something can take care of the grunt
> > work.
>
> Have you looked at Maypole yet?
>
> http://maypole.simon-cozens.org/
>
> (caveat, I haven't actually used it yet, but I've read enough about it
> to be pretty excited, now I just need to make some time to play with
> it...)
I've not used it either but I was impressed when I saw it demonstrated.
It uses Template::Toolkit and Class::DBI in an almost magical way :-)
P
--
pkent 77 at yahoo dot, er... what's the last bit, oh yes, com
Remove the tea to reply
------------------------------
Date: Tue, 11 May 2004 18:05:15 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: read from comma delimited file
Message-Id: <Xns94E68F4DD71BEdkwwashere@216.168.3.30>
I wrote:
[re mispelling in 'perldoc -q delimited']
> I sent in a bug report, and mentioned this thread.
Mail to perlbug@perl.org has bounced on two separate attempts. Does
anyone know what is happening? Email to other places doesn't bounce,
so the problem doesn't seem to be on my end.
------------------------------
Date: Tue, 11 May 2004 21:58:23 GMT
From: Don Stefani <dev_mail@donstefani.com>
Subject: RegExp in one statement
Message-Id: <30coc.47437$DF7.39076@newssvr29.news.prodigy.com>
How can I do this in one statement?
my $ml_name = $q->param('ml_name');
$ml_name =~ s/^(\s*)//;
Thanks
- dstefani
------------------------------
Date: Tue, 11 May 2004 16:13:04 GMT
From: Vik Rubenfeld <vikr@mindspring.com.invalid>
Subject: Regular Expression Help? - Newbie Question
Message-Id: <vikr-6CA054.09130411052004@news4.west.earthlink.net>
I'm trying to remove html <b> and </b> tags from some text. It's for a
weblog, and I'm using a weblog plugin called MTRegEx that implements
regex search and replace. Here's an example of what I tried so far:
<MTRegexDefine name="RemoveBoldFacing1">s|^\s*<b>||gi</MTRegexDefine>
<MTRegexDefine name="RemoveBoldFacing2">s|\s*<\b>||gi</MTRegexDefine>
Can anyone tell me the correct search and replace pattern for this?
Thanks in advance to all for any info.
-Vik
------------------------------
Date: Tue, 11 May 2004 14:16:56 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Regular Expression Help? - Newbie Question
Message-Id: <20040511140821.F25082@dishwasher.cs.rpi.edu>
On Tue, 11 May 2004, Vik Rubenfeld wrote:
> I'm trying to remove html <b> and </b> tags from some text. It's for a
> weblog, and I'm using a weblog plugin called MTRegEx that implements
> regex search and replace. Here's an example of what I tried so far:
>
> <MTRegexDefine name="RemoveBoldFacing1">s|^\s*<b>||gi</MTRegexDefine>
> <MTRegexDefine name="RemoveBoldFacing2">s|\s*<\b>||gi</MTRegexDefine>
>
> Can anyone tell me the correct search and replace pattern for this?
>
> Thanks in advance to all for any info.
First off, nothing you've said here indicates that this Weblog plugin
actually uses Perl regular expressions. Regular Expressions are not a
universal constant. The syntax and grammar are dependent on the
implementation. You would have to consult this system's documentation to
learn the correct grammar.
Secondly, assuming you are positive these are indeed Perl regular
expressions, I must ask why you are anchoring to the start of the string.
What happens if a string contains:
"This is some <b>bold</b> text"
Your initial regexp will miss that because you are only looking for <b>
occuring at the start of the string (possibly preceeded by whitespace.
Thirdly, are you sure you want to be removing the whitespace that's coming
before the <b> tag? That could likely cause words to end up squished
together. Why are you deleting that whitespace?
So, given all that, I would make a regexp of
s|</?b>||gi
HOWEVER, note that this will not match every possible tag. For example,
what if the tag looks like this: <b >bold </b > ? The expression above
could of course be modified to take this into account. However....
Fourthly, I wish to point out that in Perl, HTML parsing is usually
not done with Regular Expressions, but instead with one of the many
modules available on CPAN. I do not know if these will work for your
weblogging software.
Paul Lalli
------------------------------
Date: Tue, 11 May 2004 18:51:32 GMT
From: Vik Rubenfeld <vikr@mindspring.com.invalid>
Subject: Re: Regular Expression Help? - Newbie Question
Message-Id: <vikr-2BAC32.11513211052004@news4.west.earthlink.net>
Paul Lalli <ittyspam@yahoo.com> wrote:
> So, given all that, I would make a regexp of
> s|</?b>||gi
That worked! Thanks very much, Paul, for this and for your helpful
explanation of how it worked.
-Vik
------------------------------
Date: Tue, 11 May 2004 15:18:30 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Regular Expression Help? - Newbie Question
Message-Id: <slrnca2d8m.4ec.tadmc@magna.augustmail.com>
Vik Rubenfeld <vikr@mindspring.com.invalid> wrote:
> Paul Lalli <ittyspam@yahoo.com> wrote:
>
>> So, given all that, I would make a regexp of
>> s|</?b>||gi
>
> That worked!
But only for a limited set of data.
It will fail with all kinds of legal HTML...
> Thanks very much, Paul, for this and for your helpful
> explanation of how it worked.
Did you hear him when he said not to use a regular expression
for parsing HTML?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 11 May 2004 16:42:17 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Regular Expression Help? - Newbie Question
Message-Id: <20040511164109.P25082@dishwasher.cs.rpi.edu>
On Tue, 11 May 2004, Tad McClellan wrote:
> Vik Rubenfeld <vikr@mindspring.com.invalid> wrote:
> > Paul Lalli <ittyspam@yahoo.com> wrote:
> >
> >> So, given all that, I would make a regexp of
> >> s|</?b>||gi
> >
> > That worked!
>
>
> But only for a limited set of data.
>
> It will fail with all kinds of legal HTML...
>
>
> > Thanks very much, Paul, for this and for your helpful
> > explanation of how it worked.
>
>
> Did you hear him when he said not to use a regular expression
> for parsing HTML?
See, I was afraid of that. This is what happens when I try to walk the
line between answering what was asked, and answering what *should have*
been asked.
Paul Lalli
------------------------------
Date: Tue, 11 May 2004 17:06:47 +0200
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: Searching CPAN by regexps
Message-Id: <40a0ec07$0$26349$9b4e6d93@newsread4.arcor-online.net>
Irving Kimura schrieb:
> Actually, as I've just found even CPAN.pm's regexp support is
> limited. For example, it doesn't recognize \W:
>
> cpan> m /\Wedge/
> Module id = SVG::Graph::Glyph::wedge
You're misinterpreting the result. You've got to quote
the backslash. Try
cpan> m /\\Wedge/
and you will indeed get
> Module Image::Filter::Edge (B/BE/BEATNIK/Image-Filter-0.07.tar.gz)
> Module Meta::Projects::Fortune::Edge (V/VE/VELTZER/Meta-0.08.tar.gz)
> Module Meta::Projects::Md5::Edge (V/VE/VELTZER/Meta-0.08.tar.gz)
> Module WordNet::Similarity::edge (S/SI/SID/WordNet-Similarity-0.06.tar.gz)
>
> instead.)
-Christian
------------------------------
Date: Tue, 11 May 2004 18:47:49 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: Using match variables ($1, $2 ...) as variables.
Message-Id: <c7r71j$5u8$1@news.simnet.is>
"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnca1hkm.3nt.tadmc@magna.augustmail.com...
> gnari <gnari@simnet.is> wrote:
>
> > my @matches = $string =~ /<Size>(\d+)</Size>([^<]*)/gs;
>
>
> m//s only affects dot.
>
> You never need a m//s when there is no dot in the pattern.
yep. had started with (.*), and changed it to ([^<]*) ,but
forgot to take the /s out.
------------------------------
Date: Tue, 11 May 2004 19:36:16 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Using match variables ($1, $2 ...) as variables.
Message-Id: <x7y8nyiwnj.fsf@mail.sysarch.com>
>>>>> "g" == gnari <gnari@simnet.is> writes:
g> "Tad McClellan" <tadmc@augustmail.com> wrote in message
g> news:slrnca1hkm.3nt.tadmc@magna.augustmail.com...
>> gnari <gnari@simnet.is> wrote:
>>
>> > my @matches = $string =~ /<Size>(\d+)</Size>([^<]*)/gs;
>>
>>
>> m//s only affects dot.
>>
>> You never need a m//s when there is no dot in the pattern.
g> yep. had started with (.*), and changed it to ([^<]*) ,but
g> forgot to take the /s out.
i have been there and done that. :)
that is a useful regex transform to know. mastering regular expressions
covers it well.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Tue, 11 May 2004 14:50:46 -0700
From: Ravi Parimi <parimi@none.nowhere.com>
Subject: Re: Using match variables ($1, $2 ...) as variables.
Message-Id: <Pine.GSO.4.58.0405111449370.25603@shelltoe.ece.arizona.edu>
> > Hi,
> > I have a string that gets generated on the fly. Based on the
> > number of times a particular word appears in this string, I generate my
> > matching pattern. As an example..
> >
> > $string = "<Data><Size>12</Size>one string<Size>100</Size>Another
> > string</Data>";
> >
> > Now, based on the number of <Size> tags in the string, I create a regular
> > expression such as
> >
> > my $count = $string =~ s#<Size>##gs;
> > my $str = "";
> > for ($i = 1;$i <= $count;++$count) {
> > $str .= "<Size>(\\d+)</Size>(.*)";
> > }
> >
> > And now I wish to extract all odd-numbered match variables from the
> > matching($1, $3, $5 etc..)
> >
> > $string =~ /$str/; # Match always succeeds as I know what's in $string
> >
> > In a for loop, I wish to check if each of the $1,$2,$3...variables are
> > defined, and am not quite sure how to do that.
> >
> >
> > Usage of ${$i} is incorrect and doesnt make sense. Can someone suggest a
> > method by which I can find out if $1, $2, $3 ..are defined?
> >
> >
> > As an alternative, I have tried XML Parser to parse the above string but
> > had no luck with it.. Any help is appreciated.
> >
> > Thanks,
> > --ravi
>
> Perhaps you are trying to overcomplicate the solution. Look at this:
>
> my $string = "<Data><Size>12</Size>one string<Size>100</Size>Another
> string</Data>"; # <-- this string should not be wrapped
> my @rows = ($string =~ /<Size>(\d+)<\/Size>/gi);
> foreach (@rows) {
> print "$_\n";
> }
>
> That snippet of code produces this:
> 12
> 100
>
> When you capture the result of the pattern match ("my @rows =...") in
> list context, you get all of the matches as a list.
>
> Is that what you want to accomplish?
This was what I was exactly looking for. It looks a lot more less
complicated than what the other posters suggested. Thanks a lot for your
help :)
--ravi
------------------------------
Date: Tue, 11 May 2004 14:52:35 -0700
From: Ravi Parimi <parimi@none.nowhere.com>
Subject: Re: Using match variables ($1, $2 ...) as variables.
Message-Id: <Pine.GSO.4.58.0405111450560.25603@shelltoe.ece.arizona.edu>
> ...
> > I have a string that gets generated on the fly. Based on the
> > number of times a particular word appears in this string, I generate my
> > matching pattern. As an example..
> >
> > $string = "<Data><Size>12</Size>one string<Size>100</Size>Another
> > string</Data>";
> >
> > Now, based on the number of <Size> tags in the string, I create a regular
> > expression such as
> >
> > my $count = $string =~ s#<Size>##gs;
>
>
> Why do you have the "s" modifier on this regexp? You don't use the .
> metacharacter in it, and the "s" modifiers only purpose is to change the
> behavior of the . metacharacter.
It was a typo. I should've posted my complete code rather than typing
snippets here and there..
> Check out:
>
> perldoc perlvar
>
> in particular the part where it talks about the @- and @+ variables.
> These give you programmatic access to the $1, $2, etc variables, via
> substr() and the variable you matched the pattern against.
Thanks for the pointer to perlvar. I didnt know that @-,@+ existed prior
to reading this.
--ravi
------------------------------
Date: Tue, 11 May 2004 14:54:43 -0700
From: Ravi Parimi <parimi@none.nowhere.com>
Subject: Re: Using match variables ($1, $2 ...) as variables.
Message-Id: <Pine.GSO.4.58.0405111453160.25603@shelltoe.ece.arizona.edu>
> > I have a string that gets generated on the fly. Based on the
> > number of times a particular word appears in this string, I generate my
> > matching pattern. As an example..
> >
> > $string = "<Data><Size>12</Size>one string<Size>100</Size>Another
> > string</Data>";
> >
> > Now, based on the number of <Size> tags in the string, I create a regular
> > expression such as
> >
> > my $count = $string =~ s#<Size>##gs;
> > my $str = "";
> > for ($i = 1;$i <= $count;++$count) {
> > $str .= "<Size>(\\d+)</Size>(.*)";
> > }
> >
> > And now I wish to extract all odd-numbered match variables from the
> > matching($1, $3, $5 etc..)
> >
> > $string =~ /$str/; # Match always succeeds as I know what's in $string
> >
> > In a for loop, I wish to check if each of the $1,$2,$3...variables are
> > defined, and am not quite sure how to do that.
>
> A more natural solution would be changing the pattern accordingly. You
> always add two pairs of capturing parens. What is the second pair for?
>
> Other than that, do the pattern match in list context and extract the
> uneven elements from the array:
>
> my @matches = $string =~ /$str/;
> @matches = map { $_ % 2 ? $matches[$_] : () } 0 .. $#matches;
You solution also worked for me prefectly. Thanks a lot for your reply!
I took care of the greedy matching problem as suggested by Gnari and Tad.
--ravi
------------------------------
Date: Tue, 11 May 2004 13:17:29 -0400
From: lmm <>
Subject: Win32::GetOSVersion - A Better Way?
Message-Id: <5nu1a0h05j3u794qppnd62rot48a2mmdl8@4ax.com>
Wondering about a better way to use Win32::GetOSVersion. I know I'll
only be dealing with W2K & WinXP. So all I need to know (I think) is
$minor. Not too sure what $string does (despite RTFM and using LP on
Win32 [Schwartz]) and $id seemed to need to be there too. What do you
think?
The important bits are:
use Win32 ;
my ($string, $minor, $id)= Win32::GetOSVersion() ;
my @OS = qw(W2K XP) ;
if (@OS eq "W2K") {
open (HOSTS, '+> C:/WINNT/system32/drivers/etc/hosts') ; #W2K
} else {
open (HOSTS, '+> C:/WINDOWS/system32/drivers/etc/hosts') #XP
or die "There is no hosts file." ; #Overwrites hostsfile
}
The working snippet of the script is below;
====================================================
use warnings ;
use strict ;
use Win32 ;
my ($string, $minor, $id)= Win32::GetOSVersion() ;
print "This program launches our VPN Client and mounts network
drives.\n" ;
print "Are you using the VPN or NOT? Enter VPN or NOT: " ;
my $loc = <STDIN>;
chomp $loc;
$loc =~ tr/A-Z/a-z/; #needlessly sets lowercase
# print $loc;
if ($loc eq "vpn" or $loc eq "not") {
} else {
print "\n******\nNo changes made to hosts file.\n" ;
print "VPN not activated!\n******\n" ;
print "Press any key to exit.\n" ;
print `pause` ;
exit () ; # exit () works better than die here
}
$loc =~ s/vpn/v/; #needlessly sets STDIN to one letter
$loc =~ s/not/n/; #needlessly sets STDIN to one letter
# print $loc;
my @OS = qw(W2K XP) ;
my $vpn = ("# VPN Hosts File
127.0.0.1 localhost
***Bunch of host file stuff***
") ;
my $not = ("# Standard Hosts File
127.0.0.1 localhost
") ;
if (@OS eq "W2K") {
open (HOSTS, '+> C:/WINNT/system32/drivers/etc/hosts') ; #W2K
} else {
open (HOSTS, '+> C:/WINDOWS/system32/drivers/etc/hosts') #XP
or die "There is no hosts file." ; #Overwrites hostsfile
}
------------------------------
Date: Tue, 11 May 2004 19:14:48 GMT
From: spamtotrash@toomuchfiction.com (Kevin Collins)
Subject: Re: Win32::GetOSVersion - A Better Way?
Message-Id: <slrnca29h8.nef.spamtotrash@doom.unix-guy.com>
In article <5nu1a0h05j3u794qppnd62rot48a2mmdl8@4ax.com>, lmm wrote:
> Wondering about a better way to use Win32::GetOSVersion. I know I'll
> only be dealing with W2K & WinXP. So all I need to know (I think) is
> $minor. Not too sure what $string does (despite RTFM and using LP on
> Win32 [Schwartz]) and $id seemed to need to be there too. What do you
> think?
>
> The important bits are:
>
> use Win32 ;
> my ($string, $minor, $id)= Win32::GetOSVersion() ;
>
> my @OS = qw(W2K XP) ;
>
>
> if (@OS eq "W2K") {
> open (HOSTS, '+> C:/WINNT/system32/drivers/etc/hosts') ; #W2K
> } else {
> open (HOSTS, '+> C:/WINDOWS/system32/drivers/etc/hosts') #XP
> or die "There is no hosts file." ; #Overwrites hostsfile
> }
>
-snip-
You can always just use:
my $minor = (Win32::GetOSVersion())[1];
Or better yet (after 30 seconds of _READING_ the docs -listed right after
Win32::GetOSVersion()), I found this which is more appropriate to your script:
Win32::GetOSName()
[EXT] In scalar context returns the name of the Win32 operating system being
used. In list context returns a two element list of the OS name and whatever
edition information is known about the particular build (for Win9x boxes) and
whatever service packs have been installed. The latter is roughly equivalent to
the first item returned by GetOSVersion() in list context. Currently the
possible values for the OS name are
Win32s Win95 Win98 WinMe Win2000 WinXP/.Net WinNT3.51 WinNT4
This routine is just a simple interface into GetOSVersion(). More specific or
demanding situations should use that instead. Another option would be to use
POSIX::uname(), however the latter appears to report only the OS family name
and not the specific OS. In scalar context it returns just the ID.
Kevin
------------------------------
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 6554
***************************************