RE: Introduction to Perl 07-07-2013, 05:57 PM
#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.

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 ]
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]
![[+]](https://sinister.ly/images/modern/collapse_collapsed.png)
![[Image: T4OUWZ1.png]](http://i.imgur.com/T4OUWZ1.png)