perl

Storing a hash in memory

Hi, I have 1 GB file of tables with data separated by columns. I have parsed it and stored in hash. Later on I am using this hash for my further work. But during developing my code each time I compile for testing the " parsing and storing into hash" is executed and which makes my program slow. Is there any way where I can store it so ...

perl print statement

can anybody explain me this print statement in the following perl program. #! /usr/bin/perl use strict; my %hash; &Parse('first.txt'); &Parse('second.txt'); my $outputpath = 'output.txt'; unlink ($outputpath); open (OUTPUT, ">>$outputpath") || die "Failed to open OUTPUT ($outputpath) - $!"; print OUTPUT "$_ \t" . join("\t", ...

best way to write code to compile with strict

What is the best way to check arguments provided to subroutines to compile with strict ( my solution works but there is a better way of doing it ? ) I have a large old library, I want to correct the code so I can add use strict; to it, most of my error are like this (on a page load it generates 189 errors): Use of uninitialized value i...

Perl hash key determined by array

I have an array and I am making a hash instance from it. For instance, if array is: @folders=(temp,usr,bin); then i want to fill in hash: $the_path{$folders[0]}{$folders[1]}{$folders[2]}="somevalue"; But if the array is only: @folders=(bin); then i want the path to be: $the_path{$folders[0]}="somevalue"; The problem is I don...

perl chomp problem

I have a situation where I need to read a file full of numbers in perl. This works fine in and of itself, but when I try to chomp each line it's turning the numbers that used to be 5 or 6 digits into either 1 or 0. Ideas? I need to chomp the numbers to assemble file paths with them so the carriage returns are a problem. ...

Splitting a changing string with perl

I have a bunch of strings in perl that all look like this: 10 NE HARRISBURG 4 E HASWELL 2 SE OAKLEY 6 SE REDBIRD PROVO 6 W EADS 21 N HARRISON What I am needing to do is remove the numbers and the letters from before the city names. The problem I am having is that it varies a lot from city to city. The data is almost never the same. Is...

Perl regular expression and capture buffer numbering

I have a file that contains hundreds of lines of the form long long int FILE_FORMAT_HEADER.file.index 1.4 3 I don't care about anything except those two numbers at the end: 1.4 and 3. I'm using the following regular expression: $line =~ m/.+\s+(\d+(\.\d+)?)\s+(\d+(\.\d+)?)/ The idea being to read as much...

How can I print specific lines from a file in Unix?

I want to print certain lines from a text file in Unix. The line numbers to be printed are listed in another text file (one on each line). Is there a quick way to do this with Perl or a shell script? ...

CRLF translation with Unicode in Perl

I'm trying to write to a Unicode (UCS-2 Little Endian) file in Perl on Windows, like this. open my $f, ">$fName" or die "can't write $fName\n"; binmode $f, ':raw:encoding(UCS-2LE)'; print $f, "ohai\ni can haz unicodez?\nkthxbye\n"; close $f; It basically works except I no longer get the automatic LF -> CR/LF translation on output that...

How do I implement object-persistence not involving loading to memory?

I have a Graph object (this is in Perl) for which I compute its transitive closure (i.e. for solving the all-pairs shortest paths problem). From this object, I am interested in computing: Shortest path from any vertices u -> v. Distance matrix for all vertices. General reachability questions. General graph features (density, etc). T...

How to do perl inline regex without setting to a variable?

Normally if you wish to change a variable with regex you do this: $string =~ s/matchCase/changeCase/; But is there a way to simply do the replace inline without setting it back to the variable? I wish to use it in something like this: my $name="jason"; print "Your name without spaces is: " $name => (/\s+/''/g); Something like tha...

Perl: Why is it slower to declare (my) variables inside a loop?

What's the difference, from the interpreter's POV, between the following the following programs: #!/usr/bin/perl -w use strict; for (1..10000000) { my $jimmy = $_**2; } and #!/usr/bin/perl -w use strict; my $jimmy; for (1..10000000) { $jimmy = $_**2; } "time" reports for the first program: real 0m1.519s user 0m...

How do I best pass arguments to a Perl one-liner?

Hi, I have this file like this: $cat a hdisk1 active hdisk2 active I use this shell script to check: $cat a.sh #!/usr/bin/ksh for d in 1 2 do grep -q "hdisk$d" a && echo "$d : ok" done Trying to convert this to Perl like this: $cat b.sh #!/usr/bin/ksh export d for d in 1 2 do cat a | perl -lane 'BEGIN{$d=$ENV{'d'};} print...

How to link library to compile/install a Perl module manually?

I want to compile/install a Perl module that depends on a library that is not in Strawberry Perl 5.12. I used Strawberry on a Windows box to install the module (Net-SSH2). The installation failed because it requires the library (libssh2). My issue is similar to this guy's http://www.perlmonks.org/bare/?node_id=814455. But I cannot use th...

Where can I read a clear explanation of POE (Perl Object Environment)?

I am searching for about a week for a good and clear tutorial for POE that is relevant to 2010 and didn't find one. I found some tutorials in the Stack Overflow question Where can I find books or tutorials for Perl’s POE? under the poe tag but most of the materials are old and not clear. Could someone provide a clear link/lecture/tutor...

how to do system() without relaying stdout in perl

How can I in perl make system("xcodebuild"); only relay stderr, and not stdout. (xcodebuild has an enormous amount of verbosity that I want to get rid of, but when something goes wrong, I still want to know what it was) ...

proxy with perl script

#!/usr/bin/perl -w use IO::Socket; my $sock = new IO::Socket::INET ( PeerAddr => 'remotehost', PeerPort => '1230', Proto => 'tcp', ) or die "ERROR in Socket Creation : $!\n"; print "TCP Connection Success.\n"; # write on the socket to server. $data = "this is the data to send"; $socket->send($data); # read the socket dat...

Using Ruby, Perl, or Python, how to "Move the window 'Firefox' to coordinate (0,0) on screen and resize it 1024 x 768"?

Can it be moved by Window Title as well as exe name? Other info on moving it in another language could be helpful. Update: some Perl sample can be found in Win32::GuiTest but there seems to be no resize or move functions. ...

Intimation from PSQL trigger

In my program, I am accessing Postgresql database. I don't want to watch database regularly, So When ever the specified table get changed by various actions ( insert, update, delete ), I need to get some signal or message to my program, So I have an idea to use Triggers, But I don't know how to send signal or API or message to my prog...

How can I improve this program to get 24 with 4 numbers?

24 points is small game. You must use + - * / to get the result 24 from 4 numbers. I wrote a Perl script to solve this problem. But I feel my code is too long and it looks like C. I hope someone can give me some advice. Thank you very much! Other language are possible, too, for example Python, Scala, F#, C++. my @test_arr = (10, 4...