Sinisterly
Introduction to Perl - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Coding (https://sinister.ly/Forum-Coding)
+--- Forum: Coding (https://sinister.ly/Forum-Coding--71)
+--- Thread: Introduction to Perl (/Thread-Introduction-to-Perl)

Pages: 1 2 3


RE: Introduction to Perl - ArkPhaze - 07-07-2013

(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.


RE: Introduction to Perl - ArkPhaze - 07-07-2013

(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.


RE: Introduction to Perl - ArkPhaze - 07-07-2013

(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.


RE: Introduction to Perl - Legolas - 07-17-2013

@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-


RE: Introduction to Perl - noize - 08-11-2013

(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.


RE: Introduction to Perl - noize - 08-11-2013

(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.