If
you have a question on how to do something in Perl, or
you need a Perl solution to an actual real-life problem, or
you're unsure why something you've tried just isn't working...
then this section is the place to ask. Post a new question!
However, you might consider asking in the chatterbox first (if you're a
registered user). The response time tends to be quicker, and if it turns
out that the problem/solutions are too much for the cb to handle, the
kind monks will be sure to direct you here.
Kindly suggest a module that I can use to create CGI/Apache Perl Scripts.
I am planning to create scripts that will pull information from a few SAN Storage Arrays and display it in a webpage. The script will be running on a Win 2003 32 Bit Server. There are chances that I could get access to a Linux Box (Redhat 5.8) from which I can run the scripts as well, so will have to create the scripts accordingly.
Before trying out anything on the office servers, I am planning to play around with it on my personal laptop, but it runs on Ubuntu 12.04. Should I install CentOS/Scientific Linux on my laptop and then try Apache or no need to do so? Because from what I have seen so far, there is a vast difference between the two Linux Versions.
I will be extremely thankful if someone could answer the questions.
Perlpetually Indebted To PerlMonks
use Learning::Perl;
use Beginning::Perl::Ovid;
print "Awesome Books";
I want to realize such a function that it can cut some columns from one variable and returns them to an other variable, it also allows me to choose the columns and the separators arbitrary.
E.g. I want to extract the 2nd, 3rd and 5-7th columns from $source and save them into $dest, and the separators for the columns can be space, # or =.
Are there any easy ways to implement this function?
I am running DBI version 1.616 along with DBD::Sybase version 1.12 to connect to the Sybase IQ 15.4 server through one of my Perl modules. The platform is IBM AIX 5.3.0.0 maintenance level 5300-12
The problem that I am facing is that one of my simple queries randomly hangs for no apparant reason. The query is to select some data from the system view SYS.SYSTABLE. The code runs fine as such but every once in a while the code (execute statement) freezes and appears to be doing noting for a long time and I have to terminate the process forcibly.
Below is a fragment of code that I'm running (all variables are properly defined):
AutoCommit is set to 1
RaiseError is set to 1
$dsn = "dbi:Sybase:serverType=IQ:loginTimeout=240:server=$db_server_if
+c";
my $dbh = DBI->connect($dsn,
$self->get_db_username(),
$self->get_db_password(),
\%connect_options );
my $sqlA =<< "END_SQLA";
SELECT table_id
FROM sys.systable
WHERE table_name like '${uc_table_name}%'
AND length(table_name) = $table_name_len
AND user_name(creator) = '$uc_schema'
END_SQLA
my $sthA = $dbh->prepare($sqlA);
$sthA->execute();
Can someone help me figure out what might be wrong with the code or if any of the modules versions that I am using are incompatible with Sybase IQ 15.4.
Another interesting thing to note is that the same code works fine most of the times, but the problem occurs randomly at random times. I have checked the active connections in my database when the code hangs, there are no deadlocks or blocked processes. I can also see that the connection to DB is being established successfully but I do not see any active executing statements at all for the DB handle.
What I want is to edit my text file using perl script. I want all the lines to be in one line which start with '+' sign, and leave rest of lines as it is. So, whenever it encounters '+' sign, script should print all the lines in one single line and then removes the '+' sign.
I would appreciate any kind of help or ideas to build this script. Thank you
i try to translate big text files with composite charsets to a constant UTF8 encoding.
anyway my investingation to this topic run into a black whole of nescience.. whats the best way to do it especially with perl?
perhaps you can give me hints or some "simple" explanations how you would do it? i know that there are CPAN::modules to identify "non-utf8" chars but on which level? is it sensefull to take the binary way or to make a comparison on the hexadecimal level?
this is the first time i really get involved with perl into the whole charset jungle..
i´m still mindmapping ;))
kindly, perlig
---- UPDATE ----
Ok. Maybe the Input looks like this:
Textfile with 100 Chars:
40 of them were Italian (it) iso-8859-1, windows-1252
20 of them were Greek (el) iso-8859-7
all others UTF8
(see e.g. http://www.w3.org/International/O-charset-lang.html)
Now i want to process this data.. but my parser is only able to read utf8.
for that i have to encode these 60 "non-utf8" chars to utf8 on a certain way..
got it? :)
i´m nearly overstrained :P can you mabe tell me something about the existing guessing modules?!
I am writing MAP REDUCE in PERL SCRIPT. I have written a MAP that outputs Key Value pair and I am writung a REDUCE to work on that Key Value Pair.
The MAP command output is fed to the REDUCER and I am trying to create a hash of Key Value pair in reducer. But the hash is empty when I feed the data to it.
The MAP is giving a proper output.
I am facing a problem while creating the hash. Also I need to add the values of hash key that are same. How do I do that
MAP
#!/usr/bin/perl
open (MYFILE, "$ARGV[0]")or die $!;
while ( <MYFILE> ) {
chomp;
(my $txnid,my $date,my $custid,my $amount, my $productc, my $subc, my
+$city, my $state, my $mode) = split(",");
my $key_to_reduce = join ".", "$subc", "$state";
print "$key_to_reduce\t$amount \n";
}
close(MYFILE);
REDUCE
#!/usr/bin/perl
my %worth = ();
while (<>) {
chomp;
(my $combined, my $value) = split ("\t");
print "Key to Reducer is:$combined \n";
print "Value of the key:$value \n";
$worth{$combined} = $value;
}
print "The hash is: %worth";
foreach my $key ( keys %worth ) {
print "key: $combined, value: $worth{$combined}\n";
}
REDUCE OUTPUT
Key to Reducer is:Fencing.Missouri
Value of the key:169.68
Key to Reducer is:Cheerleading.California
Value of the key:078.61
Key to Reducer is:Field Hockey.Texas
Value of the key:085.64
Key to Reducer is:Weightlifting Belts.Florida
Value of the key:030.48
............
key: , value:
key: , value:
key: , value:
key: , value:
key: , value:
key: , value:
key: , value:
key: , value:
key: , value:
MAP OUTPUT
notroot@ubuntu:~/lab/programs$ perl transaction_map.pl /home/notroot/l
+ab/data/txns | more
Cardio Machine Accessories.Tennessee 040.33
Weightlifting Gloves.California 198.44
Weightlifting Machine Accessories.California 005.58
Gymnastics Rings.Wisconsin 198.19
Field Hockey.Tennessee 098.81
DATA
00000000,06-26-2011,4007024,040.33,Exercise & Fitness,Cardio Machine A
+ccessories,Clarksville,Tennessee,credit
00000001,05-26-2011,4006742,198.44,Exercise & Fitness,Weightlifting Gl
+oves,Long Beach,California,credit
00000002,06-01-2011,4009775,005.58,Exercise & Fitness,Weightlifting Ma
+chine Accessories,Anaheim,California,credit
00000003,06-05-2011,4002199,198.19,Gymnastics,Gymnastics Rings,Milwauk
+ee,Wisconsin,credit
00000004,12-17-2011,4002613,098.81,Team Sports,Field Hockey,Nashville
+ ,Tennessee,credit
00000005,02-14-2011,4007591,193.63,Outdoor Recreation,Camping & Backpa
+cking & Hiking,Chicago,Illinois,credit
00000006,10-28-2011,4002190,027.89,Puzzles,Jigsaw Puzzles,Charleston,S
+outh Carolina,credit
00000007,07-14-2011,4002964,096.01,Outdoor Play Equipment,Sandboxes,Co
+lumbus,Ohio,credit
00000008,01-17-2011,4007361,010.44,Winter Sports,Snowmobiling,Des Moin
+es,Iowa,credit
COMMAND
perl transaction_map.pl /home/notroot/lab/data/txns | perl transaction
+_reduce.pl
Hello Perl wise ones, forgive me if I'm having my usual frustration with installing Perl modules on Windows XP with ActiveState. I specifically want to install DBD::JDBC.
I don't see it in the list when running ppm, and "ppm install DBD-JDBC" doesn't find it.
ppm install DBD-JDBC
ppm install failed: Can't find any package that provides DBD-JDBC
I also tried installing DBD::ODBC and got an "authorization required" error, but I don't know where to "authorize." ERROR: 401 Authorization Required
I tried adding cpan to the repository list in ppm (http://www.cpan.org) but zero modules are added.
I tried installing with cpan. I get dozens of errors, including a C Compiler not being installed. Just running "cpan" gives me this:
It looks like you don't have a C compiler and make utility installed.
+ Trying
to install dmake and the MinGW gcc compiler using the Perl Package Man
+ager.
This may take a a few minutes...
Downloading MinGW-5.1.4.1...redirect
Downloading MinGW-5.1.4.1...failed 401 Authorization Required
ppm.bat install failed: 401 Authorization Required
It looks like the installation of dmake and MinGW has failed. You wil
+l not be
able to run Makefile commands or compile C extension code. Please che
+ck your
internet connection and your proxy settings!
cpan shell -- CPAN exploration and modules installation (v1.9402)
Enter 'h' for help.
I looked at the instructions for installing modules on cpan.org which says you need a C compiler: "(it's easy to get this setup - don't panic), see your OS of choice below to find out how to get the right compiler." ... but couldn't find any instructions on how to install this.
Perhaps this is all related to the authorization error? Any idea how I can get running here?
I have a structure I want to test for that comes back as a hash where one of the values is 'objects' which is an array of hash objects that have 2 fields that should always be present, but a 3rd field that may sometimes be present and sometimes not be present. When it is present I'd like to verify it with a re(...) comparison, but when it isn't present I'd like to prevent an error message telling me so... because it is optional! However if any other fields show up in there that aren't known optionals, I want to know about it. Does this make sense? How can I code this with Test::Deep?
I read through the doc on cpan and noticed the superhash stuff, but I wasn't sure how to apply it with this array situation and also in such a way that met my specific needs. Any counsel would be appreciated... thanks.
my $myObjs = {
alpha => re('^alpha(.*)'),
beta => re('\d+'),
#myOptionalField => re('^opt(.*)'), #sometimes there is a "myOpti
+onalField", but sometimes there is not. What to do?
};
cmp_deeply(
$response,
{
field1 => re('\d+'),
field2 => 2,
field3 => 1,
objects => array_each($myObjs)
},
'testing for valid response structure'
);
I've been reading the Perl 5.18 delta, and now that smartmatch is both experimental and depreciated I'm in a bit of a muck. I have a big project that uses given/when quite heavily (28 givens, 85 whens).
What is the recommended way to fix this? I know I can turn off the warning, but I'd rather fix the code. The documentation says that given/when is subject to big changes and might even go away, so disabling the warning is only a temporary fix. An automatic fix would be nice, but I don't mind doing all the work by hand. I have a good test suite, so I'm not concerned about breaking things.