Perl: Using /g modifier in scalar context

When used in scalar context, the /g modifier indicates a progressive match, which makes Perl start the next match on the same variable at a position just past where the last one stopped. After a failure, the match position normally resets back to the start. Example: [code language=”perl”] C:\>perl $a = "test"; ($a =~ /test/g) ? print "Found!\n" : print "Missing!\n"; # Check again … the fun starts here ($a =~ /test/g) ? print "Found again!!\n" : print "Missing again!!\n"; # Check again … the fun starts here ($a =~ /test/g) ? print "Found after failure \n" : print "Missing […]

Read more

Perl script: Auto Detect the script file name

CODE: [code language=”perl”] use File::Basename; my $progname = basename($0); $progname =~ m/(.*)(\.)(.*)/; print "Script name along with extension: [$progname]\n"; print "Script name without extension: [$1]\n"; [/code] OUTPUT: [code language=”perl”] C:\>perl get-script-name.pl Script name along with extension: [get-script-name.pl] Script name without extension: [get-script-name] C:\> [/code]

Read more

VB script to modify shortcut properties

As part of application repackaging, you need to update some of the properties of an application shortcut as post install action of an installer. Below is the code that can be used to auto update the shortcut properties as needed. [code language=”vb”] Set sh = CreateObject("WScript.Shell") Set FSO = CreateObject("Scripting.FileSystemObject") FSO.DeleteFile("C:\ProgramData\Microsoft\Windows\Start Menu\Programs\PowerGUI\PowerGUI.lnk") Set shortcut = sh.CreateShortcut("C:\ProgramData\Microsoft \Windows\Start Menu\Programs\PowerGUI\PowerGUI.lnk") shortcut.TargetPath = "C:\Program Files\PowerGUI\AdminConsole.exe" shortcut.Arguments = "-auto none" shortcut.WindowStyle = 7 shortcut.Save [/code]

Read more