perl

Why does Perl autovivify in this case?

Why does $a become an arrayref? I'm not pushing anything to it. perl -MData::Dumper -e 'use strict; 1 for @$a; print Dumper $a' $VAR1 = []; ...

Why do my images get clipped when served by this Perl CGI script?

When I try to print an image to STDOUT in a Perl CGI script, the image gets clipped when viewed in the browser. Here is the following code: if ($path =~ m/\.jpe?g$/i) { my $length = (stat($path))[7]; $| = 1; print "Content-type: image/jpg\r\n"; print "Content-length: $length\r\n\r\n"; open(IMAGE,"<$path"); binmode(IMAG...

How can I set the size of the cmd.exe window from my Perl program?

I have a Perl script running in windows, that displays to screen very long lines. I don't want to fix my console size permanently. I just want it to be big in case this script is running. Is there a way to define the console's size from within the Perl script that runs inside this window? ...

Why does my Perl subroutine return false even though the parameters are valid?

I am trying to write a function which validates the username for an alphanumeric value and in the case of failure it should log my custom error message and return 0 to the called function instead of die-ing: sub insertUser{ my ( $username, $password, $email, $name) = validate_pos( @_, { type => SCALAR, ...

Select query question

Hello! I have a table in a mysql-database with the fields "name", "title", "cd_id", "tracks" The entries look like this: Schubert | Symphonie Nr 7 | 27 | 2 Brahms | Symphonie Nr 1 | 11 | 4 Brahms | Symphonie Nr 2 | 27 | 4 Shostakovich | Jazz Suite Nr 1 | 19 | 3 To get the tracks per cd (cd_id) I have written this script: #!/usr/bin/...

How can I programmatically add a macro to a MS Word document using Perl?

I have a Perl script that can define and write a MS Word macro according to the user's input. But how can I make the Perl script open Word and add the macro into its macros data base? ...

Is there an equivalent of PHP's mysql_real_escape_string() for Perl's DBI?

Could some tell me if there is a function which works the same as PHP's mysql_real_escape_string() for Perl from the DBI module? ...

How do I load Catalyst::Plugin::SmartURI in my main application file?

I'm working on some large Catalyst codebase which doesn't have a seperate config file. However, in the main module it does have things like: __PACKAGE__->config( name => 'Example::Server', encoding => 'UTF-8', ... ); So I was hoping I could just add the SmartURI config there, like this: __PACKAGE__->config( name => '...

getting started with vim scripting with perl

I'd like to create a vim function/command to insert an XSD style timestamp. Currently, I use the following in my vimrc file: nmap <F5> a<C-R>=strftime("%Y-%m-%dT%H:%M:%S-07:00")<CR><Esc> I'd like to use the Perl code: use DateTime; use DateTime::Format::XSD; print DateTime->now(formatter => 'DateTime::Format::XSD', time_zone => 'Amer...

Display all first-level descendant branches using Git

How can I get a list of branches that are first-level descendants of the current HEAD? I can get a list of the whole tree with: git log --graph --abbrev-commit --pretty=decorate --branches which gives * 2eff4a7... (refs/heads/issue-8351) Added a factory factory factory. * 2e387aa... Refactored all of the factory factories. | * b3fad...

How can I reuse some functions in a Perl script?

I am facing a problem that require the reuse some of the functions within another Perl script. I am writing some test scripts. The test scripts are basically build on each other. Say Script 1 does: Some code to prepare the test. A. B. C. Some code to determine the success. Then Script 2 does: Some code to prepare the test. A. B. C. ...

Capturing command-line output on win32 that hasn't been flushed yet

(Context: I'm trying to monitor a long-running process from a Perl CGI script. It backs up an MSSQL database and then 7-zips it. So far, the backup part (using WITH STATS=1) outputs to a file, which I can have the browser look at, refreshing every few seconds, and it works.) I'm trying to use 7zip's command-line utility but capture t...

Can Storable store to the DATA filehandle?

I was curious if using Storable's store_fd and fd_retrieve would allow me to store a data structure into a program's own DATA filehandle. I realize this isn't Best Practice, I'm just curious if it'd work, my quick attempts to try it don't seem to work. ...

When did the file mode in Perl's open become a separate argument?

Once upon a time, you opened files in Perl like so: open(FH, ">$filename"); At some point, for many good reasons including some very sticky ones involving filenames with leading spaces, this syntax became available (and, immediately, preferred): open(FH, '>', $filename); What version of Perl did we get that syntax with? ...

How can I make LWP::UserAgent appear to have Flash installed?

I have a Perl script that uses LWP::UserAgent to download a webpage which it then processes using regular expressions. The problem is that portions of the webpage which are regular HTML aren't being returned to LWP::UserAgent since the site recognizes that the browser doesn't have Flash installed and instead returns HTML prompting us to ...

What does the Filter::Crypto module do to the DATA section?

I'm trying to package a Perl script to EXE using the pp utility bundled with PAR::Packer with the Filter::Crypto on. But something is wrong there. Without the filter, things are ok. With it, no. I think it has something to do with the DATA section in the script. The following simplified script might demonstrate the problem but I'm not su...

Is it a good idea to warm up a cache in the BEGIN block in Perl?

Is it a good idea to warm up cache in the BEGIN block, when it gets used? ...

What should every Perl hacker know about perl -ne?

I have been using the Perl command line with a -ne option for years, largely to process text files in ways that sed can't. Example: cat in.txt | perl -ne "s/abc/def/; s/fgh/hij/; print;" > out.txt I have no idea where I learned this, and have only today read perlrun and found there are other forms (perl -pe for example). What else sh...

Why does Perl replace my string with "1"?

I have the following code: #$domain = domainname.co.uk #$root = public_html #$webpage = domainname.co.uk/foo/bar/foobar.html my $string = ($webpage =~ s/^$domain//g); my $linkFromRoot = $dbh->quote($root . $string); Usualy this works fine but for some reason the output is "public_html 1" instead of "public_html/foo/bar/foobar.html". ...

Best way to manage long-running php script?

I have a PHP script that takes a long time (5-30 minutes) to complete. Just in case it matters, the script is using cUrl to scrape data from another server. This is the reason it's taking so long; it has to wait for each page to load before processing it and moving to the next. I want to be able to initiate the script and let it be unti...