perl

How can I determine actual file size on disk using Perl?

I am scanning a file system and wish to determine the allocated size of a file on disk. Using stat() I can get the file size as ( stat(_) )[7] , the blocks allocated on disk can be obtained from ( stat(_) )[12], and the "preferred block size for file system I/O" is ( stat(_) )[11]. If I merely multiply stat column 11 and 12, however, ...

Escaping spaces when calling (buffer-file-name) in emacs

So, I had a question about getting word count to work properly in emacs LaTeX mode (auctex, actually, but never mind.) That was answered fine. Then I found I had trouble when the (buffer-file-name) included spaces. This made it mess up. This problem was got around too. Now the problem is that the solution breaks when there AREN'T any spa...

Perl: Can't pass an "on-the-fly" array to a sub

strftime(), as per cpan.org: print strftime($template, @lt); I just can't figure the right Perl code recipe for this one. It keeps reporting an error where I call strftime(): ... use Date::Format; ... sub parse_date { if ($_[0]) { $_[0] =~ /(\d{4})/; my $y = $1; $_[0] =~ s/\d{4}//; $_[0] =~ /(\d\d)\D(\d\d)/; return [$2,$1,...

disable foreign key check deleting InnoDB tables Perl Script

Am fairly new to using MySQL and a total novice at Perl but am trying to hack someone elses script to help me out. I got the script from here. It looks great so far but it fails as the tables have some foreign key check going on. I could go through phpmyadmin and try and delete them all one by one but this takes for ever and is my thi...

Problem using Perl to connect to MySQL database on remote server

I have a Perl script that gets data from a MySQL database on one server (let's call it server1), does stuff with it and writes it out to another database on another server (server2). Both servers are remote to the server that runs the Perl script. I can connect to the DB on server1 OK, but when I try to connect to the DB on server2, usi...

Capturing groups in a variable regexp in Perl

I have a bunch of matches that I need to make, and they all use the same code, except for the name of the file to read from, and the regexp itself. Therefore, I want to turn the match into a procedure that just accepts the filename and regexp as a string. When I use the variable to try to match, though, the special capture variables st...

Trouble sending email with perl

I have a program that runs every 4 hours and I want it to send an email to me when it does. So I added this: my $host = "smtp.central.cox.net"; my $message = MIME::Lite->new( From => '*********', To => '*********', Subject => 'KMZ Downloader', Data => "Successful on $now_string" ); MIM...

Perl, redirect stdout but keep on parent

In perl, after fork()ing I can redirect a child's stdout to a file like so open STDOUT,">",$filename or die $! I'm wondering if there is a way of "copying it", keeping the stdout on the parent's stdout but also copying to a specified file. It should happen in a way that would not require any buffering and the user would see the consol...

Incrementing an integer at the end of a string in perl

I have a string in the following format: \main\stream\foo.h\3 it may have more or less "sections", but will always end with a slash followed by an integer. Other examples include: \main\stream2309\stream222\foo.c\45 \main\foo.c\9 I need to, in perl, increment the number at the end of the string and leave the rest alone. I found an ...

Consuming .Net Web Service using Perl and SOAP Lite

I'm trying to consume a .Net Web Service using perl and SOAP Lite. When I consume the web service in a .Net client - it posts to the .asmx endpoint the following: <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xs...

perl plotting using GD:Graph

hello, I have data like this. file1 date1 1 76.09 date10 10 87.09 date11 11 89.89 date2 2 66.5 date3 3 78.89 date4 4 87.98 date5 5 57 date6 6 57.98 date7 7 34.32 date8 8 45.76 date9 9 34.99 file2 date1 1 82.45 date2 2 86.23 file3 date1 1 65.76 ...

Trying to create Template::Plugin::Filter for Haml

I'm trying to create a cpan module that integrates Text::Haml into Template Toolkit. I think that Haml is an interesting templating language but rather limited, it doesn't support loops or conditionals let alone more advanced things. But I can't seem to get eve a very simple version to work. The following are some test scripts that work ...

Reversing a multi-value hash in perl

I have a hash that looks like this: { bmw => { id => 1, color => brown } } { mercedes => { id => 2, color => black } } I want to reverse this hash in perl so that I just get a mapping of id => name_of_car. Do I need to use the reverse function somehow? Note: I can always iterate through the original hash and assign the keys and...

What does "Useless use of a variable in void context" mean in this Perl script?

The following script gives me what I want but Perl also throws me a warning saying "Useless use of a variable in void context". What does it mean? use strict; use warnings; my $example = 'http\u003a//main\u002egslb\u002eku6\u002ecom/c0/q7LmJPfV4DfXeTYf/1260269522170/93456c39545857a15244971e35fba83a/1279582254980/v632/6/28/a14UAJ0CeSyi3...

Perl Thread Safe Modules

I am trying to take a Perl program I wrote and thread it. The problem is I read that some modules aren't "thread safe". How do I know if a module is thread safe? I've looked around for a list and cannot locate one. To test out one module I use frequently (Text::CSV_XS) I tried the following code out: use strict; use warnings; use th...

Unicode based 'tweet compressor' in Perl

I want to implement my own tweet compressor. Basically this does the following. However I'm stuck with some of the unicode issues. Here's my script: #!/usr/bin/env perl use warnings; use strict; print tweet_compress('cc ms ns ps in ls fi fl ffl ffi iv ix vi oy ii xi nj/, "\. " ,", "'),"\n"; sub tweet_compress { my $tweet = shif...

How to make perl script thinks that it's running on 64-bit machine?

How can I make a Perl script think that it is running on 64-bit machine? It needs to perform binary parsing of data that was written on a 64-bit machine, but it needs to be parsed on a 32-bit machine (via argument flag, for example). In my code I using pack/unpack with the formatting 'L!4'. ...

Using Perl to Display GPX File on Google Map

I have a bunch of GPX files on our server and would like to overlay them on top of a Google Map to display them on our website. We use Perl for all our site scripts however we're having a hard time figuring out how to format the data correctly to display it in Google Maps. I'm hoping that some GPX expert out there can explain at a high ...

How do I compare packed values in Perl?

I want to use the pack() function in Perl to encode some data. Then I want to compare my packed structure to another packed structure. I want this compare to be on the byte values of this packed structure. According to the documentation, cmp uses the current locale to determine how to compare strings. But I don't want any intelligence a...

Regex expression to split a line to three segments in Perl

I am parsing a text file and I get multiple lines in the form shown below. Then I try to split each line to three segments: Part1: sf; part2: name; part3:direction. But now I am encountering difficulty in how to write my regular expression. I have thought about splitting on whitespace and using an array to concatenate new strings: S1...