perl

Why is 'last' called 'last' in Perl?

What is the historical reason to that last is called that in Perl rather than break as it is called in C? The design of Perl was influenced by C (in addition to awk, sed and sh - see man page below), so there must have been some reasoning behind not going with the familiar C-style naming of break/last. A bit of history from the Perl 1....

How to make an email bot that replies to users not reply to auto-responses and get itself into mail loops.

I have a bot that replies to users. But sometimes when my bot sends its reply, the user or their email provider will auto-respond (vacation message, bounce message, error from mailer-daemon, etc). That is then a new message from the user (so my bot thinks) that it in turn replies to. Mail loop! I'd like my bot to only reply to real e...

Why does my method print "isObjectName=SCALAR(0x1289df0)"?

New to OOP with Perl, and just had a quick question. I have this function in a class: sub Print{ my $text = shift; print "my text is", $text; } I try to print the text out, by doing this: my $object = ObjectName->new(); $object->Print("Print this text") It prints this: my text isObjectName=SCALAR(0x1289df0) My question is...

Do I need to use a class to use its methods in my subclass in Perl?

Alrighty, coding in Perl and just had a quick question. I have class created called SubtitleSite which is basically an abstraction, and a class called podnapisi that inherits SubtitleSite like this: @ISA = qw(SubtitleSite); My question is, do I have to use: use SubtitleSite; in order to have access to all the methods in SubtitleSit...

Is there a CPAN module that allows me to manage errors ids and i18n error messages and integrates with Exception::Class or Error?

I am looking for a CPAN module that will allow me to store possible exceptions/errors in a database and internationalize my error messages. Currently I have subclassed Exception::Class but its a bit of a hack and I would like to use something that is production quality. It would be great if it integrates with Exception::Class or even Err...

How can I use Haml with Catalyst?

Is it possible to use Haml instead of a templating engine with the Catalyst web framework? ...

How can I print a hash of hashes of hashes in Perl?

I have a $map{k1}{k2}{k3}{k4}. How can I write the loop correctly to print all values? The following does not work. for my $k1 (sort keys %tripletsCountMap) { for my $k2 (sort keys %$tripletsCountMap{k1}){ for my $k3 (sort keys %$tripletsCountMap{k1}{k2}) { for my $k4 (sort keys %$tripletsCountMap{k1}{k3}{k3}){ pr...

How do I take a reference to an array slice in Perl?

How would you take a reference to an array slice such that when you modify elements of the slice reference, the original array is modified? The following code works due to @_ aliasing magic, but seems like a bit of a hack to me: my @a = 1 .. 10; my $b = sub{\@_}->(@a[2..7]); @$b[0, -1] = qw/ < > /; print "@a\n"; # 1 2 < 4 5 6 7 > 9 10 ...

What's the difference between a hash and hash reference in Perl?

I would like to properly understand hashes in Perl. I've had to use Perl intermittently for quite some time and mostly whenever I need to do it, it's mostly related to text processing. And everytime, I have to deal with hashes, it gets messed up. I find the syntax very cryptic for hashes A good explanation of hashes and hash references...

How can I construct OS-independent file paths in Perl?

I need to construct a file path inside a Perl script. Which path separator should I use to allow my script to work on both Windows and Unix? Keep in mind that Windows needs a drive letter. ...

How do I resolve this syntax error I get when using the Perl conditional operator?

I would like to get solution for a issue on in perl program. $parallel_on=='YES'? my $pid = $pm->start and next; :0; I want being the statement like this. but I am not getting solved. Can please any one solve this? ...

Is using __PACKAGE__ inside my methods bad for inheritance?

If inside my code I'll have calls like: __PACKAGE__->method; will this limit the usability of this module, if this module is inherited? ...

How can I print print just a unix newline in Perl on Win32?

By default, perl prints \r\n in a win32 environment. How can I override this? I'm using perl to make some changes to some source code in a repository, and I don't want to change all the newline characters. I tried changing the output record separator but with no luck. Thanks! Edit: Wanted to include a code sample - I'm doing a search ...

How can I call curl from a Perl CGI script?

I have a CGI (perl) script that is attempting to call curl using the open command: @curl = ('/usr/bin/curl', '-S','-v','--location', $url, '-H', 'Content-Type:'.$content_type, '-H', "Authorization: $authorization", '-H', "X-Gdata-Key:$gdata_key", ...

Adding a library to the @INC array in perl

I am running a script which requires the Curl.pm lib in order to work. I used YUM to install the library and now I am trying to have my script use it, but I keep getting the error Can't locate WWW/Curl.pm in @INC (@INC contains: /usr/lib64/perl5/site_perl/5.8.6/x86_... When I type the following in the command line: rpm -ql curl I ge...

Why does my Perl CGI complain about "Premature end of script headers"?

I'm sure someone could answer this very quickly, but I'm just new to perl... I'm trying to modify demarc (a simple network monitoring tool) to do a system call to a simple script. The script itself does nothing, I'm just trying to do a 'proof-of-concept' because I keep getting an internal server error. Permissions to the script have bee...

How can I insert hash values in columns with Perl's DBI?

I have a hash and I am trying to insert its values into database. Hash is defined as follows: my %hash = ( 1 => 'First Word', 2 => 'Second Word is correct', 0 => 'Third word does not exist', ); I do not know how to insert values in a database using hashes. I notice my question i...

How does an object access the symbol table for the current package?

How could I access the symbol table for the current package an object was instantiated in? For example, I have something like this: my $object = MyModule->new; # this looks in the current package, to see if there's a function named run_me # I'd like to know how to do this without passing a sub reference $object->do_your_job; If in the...

How do I grab only one capture out of a Perl regular expression?

Is there an easier way to grab only one element out of a match other than doing the followng: my $date = ($xml_file =~ m/(\d+)-sys_char/)[0]; # or my $date = $1 if $xml_file =~ /(\d+)-sys_char/; Is there a flag to specify that m doesn't return an array but just one concatenated value of all the $# matches, so I can do:? my $date = ($...

Can someone point me to good articles on intermediate-level Perl syntax and idioms?

As a non-English native, I used to make a lot of English grammatical and idiomatic mistakes. For example, I would write "I will can climb Mt Everest." instead of "I will be able to climb Mt Everest" and "students learn more knowledge in school" instead of "students lean more in school". Now I'm learning Perl as my first programming langu...