perl

What is a good starter-project in Perl?

A buddy of mine wants to learn Perl. He asked me how to go about it. I told him: To learn Perl, you must first write Perl code. This was seconded by another buddy of mine who writes a lot of good Perl code. It's very zen, but not helpful. The problem is that this is exactly how I learnt to write Perl. At my very first job I had to imp...

bitwise XOR a string in Bash

Hi. I am trying to accomplish a work in Bash scripting. I have a string which i want to XOR with my key. #!/bin/sh PATH=/bin:/usr/bin:/sbin:/usr/sbin export PATH teststring="abcdefghijklmnopqr" Now how do i XOR the value of teststring and store it in a variable using bash? Any help will be appreciated. Basically i am trying to dup...

Sorting a directory in perl, taking numbers into account

I think I need some sort of Schwartzian Transform to get this working, but I'm having trouble figuring it out, as perl isn't my strongest language. I have a directory with contents as such: album1.htm album2.htm album3.htm .... album99.htm album100.htm I'm trying to get the album with the highest number from this directory (in this c...

FTP script retain timestamp of a file after put

I know that FTP does not support transferring and retaining file date/time stamps Wondering if anyone has any ideas/scripts (Shell/perl) that would retain a transfered file's timestamp after a put operation? ...

How can I specify the name of a mounted drive in Windows when mounting programmatically?

I am writing a perl routine that mounts specific drives at startup. However, when the drives are mounted, they appear in "My Computer" with odd names like "dir$ at 'machinename' (H:)". Is there a way in perl or C to specify this string (or just the 'dir$' part?) at mount-time? ...

How to post non-latin1 data to non-UTF8 site using perl?

I want to post russian text on a CP1251 site using LWP::UserAgent and get following results: # $text="Русский текст"; obtained from command line FIELD_NAME => $text # result: Г?в г'В?г'В?г'В?г?вєг?вёг?в? Г'В'Г?вчг?вєг'В?г'В' $text=Encode::decode_utf8($text); FIELD_NAME => $text ...

How can I skip some block content while reading in Perl.

Hello. I plan to skip the block content which include the start line of "MaterializeU4()" with the subroutin() read_block below. But failed. # Read a constant definition block from a file handle. # void return when there is no data left in the file. # Otherwise return an array ref containing lines to in the block. sub read_block {...

Unable to encode to iso-8859-1 encoding for some chars using Perl Encode module

I have a HTML string in ISO-8859-1 encoding. I need to pass this string to HTML:Entities::decode_entities() for converting some of the HTML ASCII codes to respective chars. To so i am using a module HTML::Parser::Entities 3.65 but after decode_entities() operation my whole string changes to utf-8 string. This behavior seems fine as the d...

Perl strings internals

How do perl strings represented internally? What encoding is used? How do I handle different encodings properly? I've been using perl for quite a long time, but it didn't include a lot of string handling in different encodings, and when I encountered a minor problem that had something to do with encodings I usually resorted to some sham...

How do I match strings in shell-style using Perl?

How to match strings in shell-style in Perl? For instance: foo* {bar,baz}.smth joe? foobar[0-9] ...

Perl : How to print all cp1252 characters on by one ?

Hi,i am not able to write a script to print all the latin -1 characters one by one.Can anybody help me in solving the problem? I am using the below code but it is not giving me expected result. foreach $char(0..255) { $hexval = sprintf("%x",$char); $charval = sprintf("%c",%hexval); print "$charval"; } output sho...

Parsing XML file with perl - regex

Hi Everyone, i'm just a begginer in perl, and very urgently need to prepare a small script that takes top 3 things from an xml file and puts them in a new one. Here's an example of an xml file: <article> {lot of other stuff here} </article> <article> {lot of other stuff here} </article> <article> {lot of other stuff here} </ar...

Which DateTime module is best for manipulating an XML date and time

I am trying to parse a date from a GPX (XML track format) that looks like 2009-08-02T12:11:06Z My initial approach was to use DateTime::Format::RFC3339 But DateTime:Format::XSD seems to do a similar job. Is there a difference between the applicability of these modules. ...

Problem with fork exec kill when redirecting output in perl

I created a script in perl to run programs with a timeout. If the program being executed takes longer then the timeout than the script kills this program and returns the message "TIMEOUT". The script worked quite well until I decided to redirect the output of the executed program. When the stdout and stderr are being redirected, the p...

Localization in Perl using gettext and Locale::TextDomain, with fallback if Locale::TextDomain is not available

The "On the state of i18n in Perl" blog post from 26 April 2009 recommends using Locale::TextDomain module from libintl-perl distribution for l10n / i18n in Perl. Besides I have to use gettext anyway, and gettext support in Locale::Messages / Locale::TextDomain is more natural than in gettext emulation in Locale::Maketext. The subsecti...

How to handle main option with Getopt

I want to handle a feature which seems to me almost natural with programs, and I don't know how to handle it with Getopt perl package (no matter Std ot Long). I would like something like: ./perlscript <main option> [some options like -h or --output-file some_name] Options will be handled with - or --, but I want to be able to let the...

Problem with the POSIX module

After moving my mod_perl site from Linux hosting to FreeBSD, I have this error in the logfile: Your vendor has not defined POSIX macro SIGRTMIN, used at ../../lib/POSIX.pm (autosplit into ../../lib/auto/POSIX/SigRt/_init.al) line 993\n The script just imports POSIX and utilizes some functions (ceil, etc) How can I solve th...

How to print a variable in reversed byte order in Perl?

Hi, I'am trying to convert the variable $num into its reverse byte order and print it out. This is what I have done so far: my $num=0x5514ddb7; my $s=pack('I!',$num); print "$s\n"; He prints it out as some non-printable characters and in a hex editor it looks right, but how can I get it readable on the console? Already tried print ...

dereferencing hash from params

Hi, This code works: my $href = shift @_; # get reference to hash my %h = %{$href}; # dereference hash This one does not: my %h = %{shift @_}; As well as this one: my %h = ${$_[0]} Why? ============================= One more time to be precisly: 1 #!/usr/bin/perl -w 2 use strict; 3 use warnings; 4 ...

How to export shell variable within perl script

I have a shell script, with a list of shell variables, which is executed before entering a programming environment. I want to use a perl script to enter the programming environment: system("environment_defaults.sh"); system("obe"); but I when I enter the environment the variables are not set. ...