Login Register


Introduction to Perl filter_list
Author
Message
RE: Introduction to Perl #21
(07-07-2013, 09:08 AM)noize Wrote: I had found some way to do that (one action per multiple cases) in Perl, but no one seems to work.

How about this?

Code:
#!/usr/bin/perl use Win32::Registry; $regKey = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"; $main::HKEY_LOCAL_MACHINE->Open($regKey, $null) || die "Open: $!"; $null->GetValues(\%ID); foreach $k (keys %ID) { if ($k eq "RegisteredOwner" || $k eq "ProductID" || $k eq "SystemRoot" || $k eq "ProductName" || $k eq "CSDVersion" || $k eq "CurrentBuild") { $entry = $ID{$k}; print "$$entry[0] = $$entry[2]\n"; } }

It works this way.

I knew it would work that way, but that's the long if statement I was trying to avoid lol. Smile

Not sure which would be more efficient, because for multiple cases, you're introducing regex, unless repetative code in the way I had it before was better, but typically with other languages you want to switch to a switch statement starting at about 5 conditions for various reasons. Not sure how Perl deals with the check in the background, but regex is also fast in Perl, so that's a tossup.
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply

RE: Introduction to Perl #22
(07-07-2013, 09:08 AM)noize Wrote: I had found some way to do that (one action per multiple cases) in Perl, but no one seems to work.

How about this?

Code:
#!/usr/bin/perl use Win32::Registry; $regKey = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"; $main::HKEY_LOCAL_MACHINE->Open($regKey, $null) || die "Open: $!"; $null->GetValues(\%ID); foreach $k (keys %ID) { if ($k eq "RegisteredOwner" || $k eq "ProductID" || $k eq "SystemRoot" || $k eq "ProductName" || $k eq "CSDVersion" || $k eq "CurrentBuild") { $entry = $ID{$k}; print "$$entry[0] = $$entry[2]\n"; } }

It works this way.

I knew it would work that way, but that's the long if statement I was trying to avoid lol. Smile

Not sure which would be more efficient, because for multiple cases, you're introducing regex, unless repetative code in the way I had it before was better, but typically with other languages you want to switch to a switch statement starting at about 5 conditions for various reasons. Not sure how Perl deals with the check in the background, but regex is also fast in Perl, so that's a tossup.
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply

RE: Introduction to Perl #23
(07-07-2013, 09:08 AM)noize Wrote: I had found some way to do that (one action per multiple cases) in Perl, but no one seems to work.

How about this?

Code:
#!/usr/bin/perl use Win32::Registry; $regKey = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"; $main::HKEY_LOCAL_MACHINE->Open($regKey, $null) || die "Open: $!"; $null->GetValues(\%ID); foreach $k (keys %ID) { if ($k eq "RegisteredOwner" || $k eq "ProductID" || $k eq "SystemRoot" || $k eq "ProductName" || $k eq "CSDVersion" || $k eq "CurrentBuild") { $entry = $ID{$k}; print "$$entry[0] = $$entry[2]\n"; } }

It works this way.

I knew it would work that way, but that's the long if statement I was trying to avoid lol. Smile

Not sure which would be more efficient, because for multiple cases, you're introducing regex, unless repetative code in the way I had it before was better, but typically with other languages you want to switch to a switch statement starting at about 5 conditions for various reasons. Not sure how Perl deals with the check in the background, but regex is also fast in Perl, so that's a tossup.
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply

RE: Introduction to Perl #24
@noize ,

i have not spent some time on Perl,yet.
But you made a nice Introduction.
It doesnt seem dificult.

Good work.
Thank you noize.

-Legolas-
[Image: T4OUWZ1.png]


Reply

RE: Introduction to Perl #25
(07-17-2013, 11:00 PM)Legolas Wrote: But you made a nice Introduction.
It doesnt seem dificult.

Good work.
Thank you noize.

-Legolas-

It's not difficult indeed, and thank you. Larry Wall wanted to make a language similar to English. While, with the time, languages far more similar to English appeared, as of 1979, I think he managed to do that quite well.

update: few edits around, like in the subroutines part; unless (under the if statement part) added; loops & goto statement added.

I'm sorry it took this long to do this, but I've been busy, and lazy. I hope I'll not need that long to write about files handling.
My Bitcoin address: 1AtxVsSSG2Z8JfjNy9KNFDUN6haeKr7LiP
Give me money by visiting www.google.com here: http://coin-ads.com/6Ol83U

If you want a Bitcoin URL shortener/advertiser, please, use this referral: http://coin-ads.com/register.php?refid=noize

Reply

RE: Introduction to Perl #26
(07-17-2013, 11:00 PM)Legolas Wrote: But you made a nice Introduction.
It doesnt seem dificult.

Good work.
Thank you noize.

-Legolas-

It's not difficult indeed, and thank you. Larry Wall wanted to make a language similar to English. While, with the time, languages far more similar to English appeared, as of 1979, I think he managed to do that quite well.

update: few edits around, like in the subroutines part; unless (under the if statement part) added; loops & goto statement added.

I'm sorry it took this long to do this, but I've been busy, and lazy. I hope I'll not need that long to write about files handling.
My Bitcoin address: 1AtxVsSSG2Z8JfjNy9KNFDUN6haeKr7LiP
Give me money by visiting www.google.com here: http://coin-ads.com/6Ol83U

If you want a Bitcoin URL shortener/advertiser, please, use this referral: http://coin-ads.com/register.php?refid=noize

Reply







Users browsing this thread: 1 Guest(s)