perl

How can I use IO::Scalar with Image::Magick::Read()?

I have an image I have manipulated with GD::Image and I want to do further manipulations with Image::Magick. I'd like to avoid writing the image out to disk just so Image::Magick can read it in. Image::Magick's Read function will accept a filehandle as a parameter, so I'm trying to pass it an IO::Scalar object I created with the output...

Perl regex not breaking out of until loop as expected.

When I print the result of the regex I am attempting to use to control the until loop it gives me the 1 or null I am expecting. Why is it that the code below won't work but if I uncomment the fifth line it works fine? print("Please enter 1, 2, 3 or 4 : "); my $channelSelection = ""; until ($channelSelection =~ /^[1-4]$/) { chomp(m...

How can I make a shell script using Perl?

I have a Perl script called replaceUp: #!/usr/bin/perl search=$1 replace=$2 find . -type f -exec perl -p -i -e "s/$search/$replace/g" {} \; The script does not get loaded. This suggests me that my script is wrong. How can you make a shell script using Perl? ...

How can I find the source location of a print statement in Perl?

How can I find the source location of a print statement in Perl? #!/usr/bin/perl foo(); bar(); sub foo { print "foo\n"; } sub bar { print "bar\n"; } The output being: >perl test.pl foo bar I'd like to somehow find be able to see (or something like) >perl test.pl main::foo> foo main::bar> bar The reason for this is I'm t...

How can I get the entire request body with CGI.pm?

I'm trying to write a Perl CGI script to handle XML-RPC requests, in which an XML document is sent as the body of an HTTP POST request. The CGI.pm module does a great job at extracting named params from an HTTP request, but I can't figure out how to make it give me the entire HTTP request body (i.e. the XML document in the XML-RPC requ...

How can I call Perl from shell script?

I have written a library in Perl that has a certain function, that gives back information about a the server as a character string. Can I call this function from a shell directly? My boss asks "Can you call it from a shell directly for the time being?" Because he said that, I think I should be able to do it, but how do I do it? ...

How do I control the variable names in Perl's Data::Dumper?

I've got this simple Perl script: #! /usr/bin/perl -w use strict; use Data::Dumper; my %foo = ( 'abc' => 1 ); print Dumper(\%foo); It outputs: $VAR1 = { 'abc' => 1 }; How do I make it output this instead? %foo = ( 'abc' => 1 ); ...

How can I mine an XML document with awk, Perl, or Python?

I have a XML file with the following data format: <net NetName="abc" attr1="123" attr2="234" attr3="345".../> <net NetName="cde" attr1="456" attr2="567" attr3="678".../> .... Can anyone tell me how could I data mine the XML file using an awk one-liner? For example, I would like to know attr3 of abc. It will return 345 to me. ...

How can I drop privileges in Perl?

I created a server program that will be started as root. After it is started I want to drop privileges to another user. How can I do this securely? ...

How do I list available methods on a given object or package in Perl?

How do I list available methods on a given object or package in Perl? ...

Why does my CGI header print as part of the body?

Hello, I am having a strange problem, maybe something to do with Apache more than Perl. In my code when I write: print "content-type: text/html\n\n"; it prints that along with the code. But when I type: $c = new CGI; $c->header(); it works fine and displays the HTML rendered output. What could the problem be? Thank you ...

How can I send email attachment without using an additional library in Perl?

Hey, I was wondering if there is a way to attach files (specifically .csv files) to a mail message in Perl without using MIME::Lite or any other libraries. Right now, I have a 'mailer function' that works fine, but I'm not sure how to adapt it into attaching files. Here is what I have: open(MAIL, "|/usr/sbin/sendmail -t"); print MAIL ...

Can I get the MD5sum of a directory with Perl?

I am writing a Perl script (in Windows) that is using File::Find to index a network file system. It works great, but it takes a very long time to crawl the file system. I was thinking it would be nice to somehow get a checksum of a directory before traversing it, and it the checksum matches the checksum that was taken on a previous run...

How can I make Perl wait for child processes started in the background with system()?

I have some Perl code that executes a shell script for multiple parameters, to simplify, I'll just assume that I have code that looks like this: for $p (@a){ system("/path/to/file.sh $p&"); } I'd like to do some more things after that, but I can't find a way to wait for all the child processes to finish before continuing. Conver...

How can I elegantly create a hash from an array reference in Perl?

Hi, I am looking for a more elegant way to create a hash that contains the list I have read in from my configuration file. Here is my code: read_config($config_file => my %config); my $extension_list_reference = $config{extensions}{ext}; my @ext; # Store each item of the list into an array for my $i ( 0 .. (@$extension_list_refere...

Why do I have problems constructing a complicated GUI using Perl-Tk on Windows?

I have a Perl-Tk GUI with about 50 sub-windows. In each sub-window there are about 50 buttons and 50 menus (each menu has about 4 options). When I run it on UNIX/Linux/Solaris, it runs smoothly. When I run it on Windows, the GUI freezes in the middle of loading so I see only some of the buttons, or the GUI doesn't show at all it seem...

How can I count unique terms in a plaintext file case-insensitively?

This can be in any high-level language that is likely to be available on a typical unix-like system (Python, Perl, awk, standard unix utils {sort, uniq}, etc). Hopefully it's fast enough to report the total number of unique terms for a 2MB text file. I only need this for quick sanity-checking, so it doesn't need to be well-engineered. ...

How can I find out how many capturing brackets are in a Perl regexp?

If I am given a rexexp in Perl, can I find out how many capturing brackets there are? So, for example: \w -> 0 (\w) -> 1 (\w(\w)) -> 2 ...

How can I extract links from an HTML file with Perl?

I have some input with a link and I want to open that link. For instance, I have an HTML file and want to find all links in the file and open their contents in an Excel spreadsheet. ...

How can I read from continuously updated file in Perl?

Greetings, I want to read through a file, go to sleep and then check if new records were written to the file. If yes I want to process the records, if no go back to sleep and check again later (in a forever loop). I thought I could do something like this but after it reads the file the first time through the while, it never seems to pic...