perl

How do I process the response as a file without using the :content_file option?

Example code: my $ua = LWP::UserAgent->new; my $response = $ua->get('http://example.com/file.zip'); if ($response->is_success) { # get the filehandle for $response->content # and process the data } else { die $response->status_line } I need to open the content as a file without prior saving it to the disk. How would you do ...

Perl: Check to see if your file was loaded as a module or run directly

How do I write a test in Perl to see if my file was run directly or imported from some other source? I'd like to do this to make it easy to bundle everything in one file but still write unit tests against the functions. My idea is to have something like this: if (running_directly()) { main(); } def main { this(); that(); } def t...

Case Sensitivity In Perl Script - How Do I Make It Insensitive?

How would I change the following markov script to treat capitalized and lowercase words as the same? The entire idea is to help increase the quality of output of my markov text generator. As it stands, if you plug 99 lowercase sentences into it and 1 capitalized sentence - you almost always find a non-markovized version of the capitali...

Perl substitution using string that contains a dollar sign on windows

I'm using perl on windows and am trying to do a one liner using perl to substitute a placeholder in a file using a windows variable that contains a dollar sign. Does anyone know what the correct usage is to make it work with the dollar sign. I've tried various ways and can't seem to get it to work. For example, I have a properties file...

What is a good way to wait until a file updated and then read from it in Perl?

I was wondering if there's a way to wait for a file to be updated, and then read from it once it's updated. So if I have file.txt, I want to wait until something new is written to it, and then read it/process it/etc. Currently I am polling using Time::HiRes::sleep(.01), but I'm wondering if there's a better way. Thanks. ...

Getting stack traces in Perl?

How do i get stack traces in perl? ...

Listing rights/roles on MS SQL Server 2005 and Analysis Services using Perl (or PHP)

As part of a project to create a tool to query all sorts of permissions relevant to users in our area at work, I need to query some information about our database servers. The servers run SQL Server 2005 (including instances of Analysis Services 2005). I need to be able to find for a given server: The list of logins on that server The...

How do I automatically copy files to my hard disk from USB device when connected using Perl?

My current thinking: I need a certain module that will let me access the USB device. Also, I need some kind of deamon thing that will notify my script of any incoming USB connection event. And then I simply use some regexp to find the file I want to copy and then do the copying, maybe with some file copy module. But I searched CPAN with...

Hashes of Array in Perl : traversal and deletion

Hi, how can i delete an element from the following hash of arrays; %HoA = ( flintstones => [ {day=>'19'}, {day=>'21'}, {day=>'22'} ], jetsons => [ {day=>'29'}, {day=>'23'}, {day=>'25'} ], simpsons => [ {day=>'26'}, {day=>'33'}, {day=>'27'} ] ); Like how can i delete e.g {day=>'21'} from flintstones and make...

Migrating to Visual Basic to perl - working with user interfaces

I've been around Visual Basic for years in high school, and I've grown up with the IDE supplied by Microsoft. It'd wonderful, but the educational and "working-model" editions of VB available to me through school don't allow me to redistribute software, as part of the EULA with Microsoft. I instead find myself working in perl to design p...

Active State Perl - IOCP

Hi People, I am thinking to use IOCP in perl in one of our network related code. Currently Active State Perl till 5.10 doesn't offer this feature? Is anyone aware of free module to use ASIO feature like IOCP in perl? -Karthik ...

Logging within utility classes

I want to adopt logging within several utility classes, e. g. DBI. What is the best practice to do it with Log::Log4perl? I think it is OK to subclass DBI (say, MyDBI) and override some methods there to make them do the logging. But there's a problem with categories. If you create a logger with Log::Log4perl->get_logger(ref $self || $s...

How to append EOF to file using Perl or Python?

I’m trying to bulk insert data to SQL server express database. When doing bcp from Windows XP command prompt, I get the following error: C:\temp>bcp in -T -f -S Starting copy... SQLState = S1000, NativeError = 0 Error = [Microsoft][SQL Native Client]Unexpected EOF encountered in BCP data-file 0 rows copied. Network packet size (by...

Perl: Encoding messed up after text concatenation

I have encountered a weird situation while updating/upgrading some legacy code. I have a variable which contains HTML. Before I can output it, it has to be filled with lots of data. In essence, I have the following: for my $line (@lines) { $output = loadstuff($line, $output); } Inside of loadstuff(), there is the following sub ...

Can't open directory, or what's wrong with my (Perl) code?

Hi all, I have a file name logspath.txt which contain on the logs directory path on the machine. one directory each line. Although the directory exist, Perl say it doesn't. #!/usr/bin/perl -w open FILE,"logspath.txt" or die $!; while (<FILE>){ print $_; opendir ($DIR,chomp($_)) or die $!; When I'm running the script I get: /h...

Parsing StarTeam command line client output

I'm trying to write a Perl script that will parse the output of the stcmd.exe (the StarTeam command line client) hist command. I'm getting the history for every file in a view and the output looks something like this: Folder: The View Name (working dir: C:\Projects\dir) History for: main.h Description: Some files Locked by: Status: Cur...

Interactive prompt in perl

What is an easy way to provide a string value to my user and let the user edit it... without him having to retype the whole string if it's not 100% correct. ...

Trouble using grammar with rakudo perl6

The simplest grammar usage gives me complation error. use v6; grammar Foo { token bar { \w+ } } say 'abc' ~~ /<Foo::bar>/; Invoked like src/rakudo/perl6 simple.p6, it fails with regex assertion not terminated by angle bracket at line 7, near "::bar>/;\n" ... I tried a number of known-to-work examples with similar results, so I ...

Perl reference a class method

Let us say if I have a Perl module Resounces.pm with this code snippet my $my_class = new MY_CLASS; our resource => { '/list' => $my_class->list_files() }; So can I call this resource variable in another perl script something similar like this? use Resources; $Resources::resource->{'/list'}; My intention is to execute list_files() ...

In Perl, how can I import a hash from a library?

I have a file revs.pm: my %vers = ( foo => "bar" ); And another file like importer.pl: use revs; How can I access %vers from importer.pl ? ...