How do I make my Perl scripts act like normal programs on Windows?

Note: The actions below require administrative privileges. For steps utilizing the command prompt it must be launched via “Run as administrator” on Windows Vista / Windows 7. Associate *.pl files with perl Run the following commands at a shell prompt: assoc .pl=PerlScript ftype PerlScript=C:\bin\perl.exe “%1” %* Replace C:\Perl\bin\perl.exe with the path to your Perl installation. … Read more

Global symbol requires explicit package name

It may also happen when the statement before is not complete. use strict; sub test; test() # some comment my $x; perl now complains with following error message: my ” Global symbol “$x” requires explicit package name The error is not in the declaration of “my”, but at the missing semicolon (;) at test().

How to parse a string into a DateTime object in Perl?

DateTime::Format::Strptime takes date/time strings and parses them into DateTime objects. #!/usr/bin/perl use strict; use warnings; use DateTime::Format::Strptime; my $parser = DateTime::Format::Strptime->new( pattern => ‘%B %d, %Y %I:%M %p %Z’, on_error => ‘croak’, ); my $dt = $parser->parse_datetime(‘October 28, 2011 9:00 PM PDT’); print “$dt\n”; The character sequences used in the pattern are POSIX standard. See … Read more

The correct way to read a data file into an array

Just reading the file into an array, one line per element, is trivial: open my $handle, ‘<‘, $path_to_file; chomp(my @lines = <$handle>); close $handle; Now the lines of the file are in the array @lines. If you want to make sure there is error handling for open and close, do something like this (in the … Read more

What’s the best way to make a deep copy of a data structure in Perl?

Clone is much faster than Storable::dclone, but the latter supports more data types. Clone::Fast and Clone::More are pretty much equivalent if memory serves me right, but less feature complete than even Clone, and Scalar::Util::Clone supports even less but IIRC is the fastest of them all for some structures. With respect to readability these should all … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)