![]() |
|
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) |
RE: Introduction to Perl - Boomslang - 07-06-2013 Great tutorial thank you
RE: Introduction to Perl - Boomslang - 07-06-2013 Great tutorial thank you
RE: Introduction to Perl - ArkPhaze - 07-06-2013 You switched over from the Perl comment style to the Lua style the second time I seen this lol: Code: -- MyBB was trimming this line, but this should be blankAlthough, Perl gets bashed quite a bit, I suppose just like any other language. What I like about Perl though, one of the good things, is that it comes with multi-threading support, and PHP does not as far as I know. Here was a script I wrote a couple years ago for System Information: 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") {
$entry = $ID{$k};
print "$$entry[0] = $$entry[2]\n";
} elsif ($k eq "ProductId") {
$entry = $ID{$k};
print "$$entry[0] = $$entry[2]\n";
} elsif ($k eq "SystemRoot") {
$entry = $ID{$k};
print "$$entry[0] = $$entry[2]\n";
} elsif ($k eq "ProductName") {
$entry = $ID{$k};
print "$$entry[0] = $$entry[2]\n";
} elsif ($k eq "CSDVersion") {
$entry = $ID{$k};
print "$$entry[0] = $$entry[2]\n";
} elsif ($k eq "CurrentBuild") {
$entry = $ID{$k};
print "$$entry[0] = $$entry[2]\n";
}
}I haven't done anything in Perl for at least a year now though. I moved onto Python instead. And I don't really like PHP. edit: Perhaps it could be improved to use a switch statement and regex to match everything since the same thing is done in each if block: 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) {
switch ($k) {
case "(RegisteredOwner|ProductId|SystemRoot|ProductName|CSDVersion|CurrentBuild)"
{ $entry = $ID{$k}; print "$$entry[0] = $$entry[2]\n"; }
}
}I can't test this anymore right now, I don't have perl installed on my machine. RE: Introduction to Perl - ArkPhaze - 07-06-2013 You switched over from the Perl comment style to the Lua style the second time I seen this lol: Code: -- MyBB was trimming this line, but this should be blankAlthough, Perl gets bashed quite a bit, I suppose just like any other language. What I like about Perl though, one of the good things, is that it comes with multi-threading support, and PHP does not as far as I know. Here was a script I wrote a couple years ago for System Information: 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") {
$entry = $ID{$k};
print "$$entry[0] = $$entry[2]\n";
} elsif ($k eq "ProductId") {
$entry = $ID{$k};
print "$$entry[0] = $$entry[2]\n";
} elsif ($k eq "SystemRoot") {
$entry = $ID{$k};
print "$$entry[0] = $$entry[2]\n";
} elsif ($k eq "ProductName") {
$entry = $ID{$k};
print "$$entry[0] = $$entry[2]\n";
} elsif ($k eq "CSDVersion") {
$entry = $ID{$k};
print "$$entry[0] = $$entry[2]\n";
} elsif ($k eq "CurrentBuild") {
$entry = $ID{$k};
print "$$entry[0] = $$entry[2]\n";
}
}I haven't done anything in Perl for at least a year now though. I moved onto Python instead. And I don't really like PHP. edit: Perhaps it could be improved to use a switch statement and regex to match everything since the same thing is done in each if block: 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) {
switch ($k) {
case "(RegisteredOwner|ProductId|SystemRoot|ProductName|CSDVersion|CurrentBuild)"
{ $entry = $ID{$k}; print "$$entry[0] = $$entry[2]\n"; }
}
}I can't test this anymore right now, I don't have perl installed on my machine. RE: Introduction to Perl - ArkPhaze - 07-06-2013 You switched over from the Perl comment style to the Lua style the second time I seen this lol: Code: -- MyBB was trimming this line, but this should be blankAlthough, Perl gets bashed quite a bit, I suppose just like any other language. What I like about Perl though, one of the good things, is that it comes with multi-threading support, and PHP does not as far as I know. Here was a script I wrote a couple years ago for System Information: 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") {
$entry = $ID{$k};
print "$$entry[0] = $$entry[2]\n";
} elsif ($k eq "ProductId") {
$entry = $ID{$k};
print "$$entry[0] = $$entry[2]\n";
} elsif ($k eq "SystemRoot") {
$entry = $ID{$k};
print "$$entry[0] = $$entry[2]\n";
} elsif ($k eq "ProductName") {
$entry = $ID{$k};
print "$$entry[0] = $$entry[2]\n";
} elsif ($k eq "CSDVersion") {
$entry = $ID{$k};
print "$$entry[0] = $$entry[2]\n";
} elsif ($k eq "CurrentBuild") {
$entry = $ID{$k};
print "$$entry[0] = $$entry[2]\n";
}
}I haven't done anything in Perl for at least a year now though. I moved onto Python instead. And I don't really like PHP. edit: Perhaps it could be improved to use a switch statement and regex to match everything since the same thing is done in each if block: 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) {
switch ($k) {
case "(RegisteredOwner|ProductId|SystemRoot|ProductName|CSDVersion|CurrentBuild)"
{ $entry = $ID{$k}; print "$$entry[0] = $$entry[2]\n"; }
}
}I can't test this anymore right now, I don't have perl installed on my machine. RE: Introduction to Perl - noize - 07-06-2013 (07-06-2013, 09:25 PM)ArkPhaze Wrote: This last script of yours does not work. On line 9, string where operator expected, so I tried removing the quotes around the brackets of the condition. Then I tried putting quotes around each one of the conditions, tried duplicating pipes, none of these worked (neither combined together). Tried also: Code: case /^(RegisteredOwner|ProductId|SystemRoot|ProductName|CSDVersion|CurrentBuild)$/and Code: case /^(?:RegisteredOwner|ProductId|SystemRoot|ProductName|CSDVersion|CurrentBuild)$/Still can't get it right. But... do you know all programming languages? :wacko: Also, I changed the comment syntax for code and code (even in the PHP code the comment style is not Perl's). RE: Introduction to Perl - ArkPhaze - 07-07-2013 As I said I can't test, and like C++, you can't do this in Perl if I remember correctly: Code: case x:
case y:
{
// case x and y
}Or any similar version of that in Perl. So for string cases, people were using Regex. And I don't know all of them, but I've fooled around with many of them. However, once you know a programming language, you pretty much know *all* of them... All of the languages I've played around with cover pretty much all of the programming syntax out there though, so even if I haven't programmed in a specific language yet, I know of one other language most of the time, that I have used, and in which is similar. Off the top of my head, I've used in the past: LISP, ASM, Batch, C, C++, C#, VB.net, PHP, Javascript, Lua, Python, PHP, OCaml, Java, Perl, F#, ObjectiveC, BASIC, Powershell, and VBS... (With maybe a couple missing) About 20% of that list though, I *truly* know as of today however. There's lots of scripting languages however that are similar to Perl though out there. RE: Introduction to Perl - noize - 07-07-2013 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. RE: Introduction to Perl - noize - 07-07-2013 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. RE: Introduction to Perl - noize - 07-07-2013 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. |