perl

Parsing and adding lines to a text file with some fields from another file

I have 2 files, one is the master file and the other is a subset of this file, with some additional data. Both the files are in the form of fields with a ^A separator. My job comes in that, from the master file, I wish to create the subset files. The subset files already have some data, which I can duplicate, but I want the fields availa...

[Perl] After querying DB I can't print data as well as text anymore to browser

I'm in a web scripting class, and honestly and unfortunately, it has come second to my networking and design and analysis classes. Because of this I find I encounter problems that may be mundane but can't find the solution to it easily. I am writing a CGI form that is supposed to work with a MySQL DB. I can insert and delete into the DB...

How can I grep for a value from a shell variable?

I've been trying to grep an exact shell 'variable' using word boundaries, grep "\<$variable\>" file.txt but haven't managed to; I've tried everything else but haven't succeeded. Actually I'm invoking grep from a Perl script: $attrval=`/usr/bin/grep "\<$_[0]\>" $upgradetmpdir/fullConfiguration.txt` $_[0] and $upgradetmpdir/fullConf...

How can I scroll a single frame in Perl Tk?

Hi everybody. I'm trying to create a GUI for a conversion program. I want to create a frame containing the log file, but I can't get it. I found some codes to make the entire window scrollable, but it's not what I want. I just want to scroll a frame containing a label with a chainging text-variable. I've even tried the following code: ...

Why does Perl::Critic dislike using shift to populate subroutine variables?

Lately, I've decided to start using Perl::Critic more often on my code. After programming in Perl for close to 7 years now, I've been settled in with most of the Perl best practices for a long while, but I know that there is always room for improvement. One thing that has been bugging me though is the fact that Perl::Critic doesn't lik...

How can I create a Perl variable name based on a string?

In Perl, is it possible to create a global variable based on a string? E.g., if I had a function like: sub create_glob_var { my ($glob_var_str) = @_; # something like this ( but not a hash access). our ${$glob_var_str}; }; and I called it like: create_glob_var( "bar" ); How could I modify create_glob_var to actually cr...

How can I learn DOCUMENT_ROOT in startup.pl under mod_perl2?

I want to learn DOCUMENT_ROOT in startup.pl, but the best I can do is to learn server_root: use Apache2::ServerUtil (); $server_root = Apache2::ServerUtil::server_root(); which is quite useless. I can set an environment variable with SetPerlEnv DOCUMENT_ROOT /path/to/www but I don't like extra configuration if possible. Is there a...

How can I access the ref count of a Perl hash?

I'm trying to enable the garbage collector of my script to do a better job. There's a ton of memory that it should be able to reclaim, but something is stopping it. I've used Devel::Cycle a bit and that's allowed me to get closer but I'm not quite there. How do I find out the current reference count for a Perl hash (the storage for my ...

How can I run Devel::Cover under mod_perl2?

Unfortunately, Devel::Cover does not yet work with threads. It doesn't work with prefork either. Being use'd in startup.pl, Devel::Cover issues Not a CODE reference. END failed--call queue aborted. perl 5.8.9, Apache 2.2.13. My OS is FreeBSD, if that matters. The same problem is reported for win32. Update: Here's output for PerlTra...

How to convert HTML to RTF in Perl?

I want a way to convert some basic html tags into RTF (like I, B, BR) Is there any simpler way to do that without paying for anything? Developing something from scratch is an option too. ...

How can I edit the SOAP envelope and header with Perl's SOAP::Lite?

I'm trying to modify the soapenv:Header to include addressing in my soap request my $header=SOAP::Header->name("Header")->prefix("soap")->uri("http://www.w3.org/2005/08/addressing"); When I send the request: print $soap->call($header, $security->value(\$userToken, $action, $message))->result; I receive the following... <"soap:Hea...

How do I replace lines in the middle of a file with Perl?

I am opening the file in append mode. I need to replace lines 2,3, and 4 in the file, and later I need to add the new data at the end of the file. ...

Why does my Perl program complain "Can't locate URI.pm in @INC"?

I'm new to Perl. I get the following error when I run a script: Can't locate URI.pm in @INC (@INC contains: /usr/local/packages/perl_remote/5.6.1/lib/5.6.1/i86pc-solaris /usr/local/packages/perl_remote/5.6.1/lib/5.6.1 /usr/local/packages/perl_remote/5.6.1/lib/site_perl/5.6.1/i86pc-solaris /usr/local/packages/perl_remote/5.6.1/lib/site_p...

What's the difference between 'for' and 'foreach' in Perl ?

I see these used interchangeably. What's the difference? ...

How can I generate a range of IP addresses in Perl?

I need to generate a list of IP-addresses (IPv4) in Perl. I have start and end addresses, for example 1.1.1.1 and 1.10.20.30. How can I print all the addresses inbetween? ...

How do I make Perl code DWIM with UTF8?

The utf8 pragma and utf8 encodings on filehandles have me confused. For example, this apparently straightforward code... use utf8; print qq[fü]; To be clear, the hex dump on "fü" is 66 c3 bc which if I'm not mistaken is proper UTF8. That prints 66 fc which is not UTF8 but Unicode or maybe Latin-1. Turn off use utf8 and I get 66 c3 ...

Why does my Perl program get a taint warning on one machine but not another?

We have two machines in our office that we are using as web servers. Both are running Perl 5.10.0. We installed an open source ticketing system, OTRS, and on one machine it runs perfectly fine but on the other we are receiving the error Insecure dependency in require while running with -T switch. I'm mystified as to why having two id...

Why does my CGI::Session keep emptying itself randomly?

The session loads fine for the most part but it is randomly clearing all of the data some times and I don't know why: Create my new session: $session = CGI::Session->new( "driver:file",undef,{Directory => '/tmp'} ); $session->param('logged_in', 1); $session->expire('logged_in', '+10m'); $session->expire('+1h'); Now when I go to ano...

Is there a good reason why I shouldn't be mixing POST and GET parameters in a CGI query?

Is there a good reason why I shouldn't be mixing POST and GET? For example: <form action="http://example.com/?param1=foo&amp;param2=bar" method="post"> ...

Can I unpack Perl dependencies to the local tree (like Ruby on Rails)?

I'm integrating with some existing, "legacy" Perl code for my current project. I'm downloading some libraries via CPAN to use in a Perl script, but I would like to avoid having all the other developers/users install these libraries manually. Taking a page from my Ruby/Rails background, I thought it might be possible to "unpack" the dep...