Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
laziness, impatience, and hubris
 
PerlMonks  

Seekers of Perl Wisdom

( #479=superdoc: print w/ replies, xml ) Need Help??

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.

User Questions
Module for trying out CGI/Apache+Perl
4 direct replies — Read more / Contribute
by perl514
on Jun 18, 2013 at 11:39

    Respected Monks,

    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";
    http://dwimperl.com/windows.html is a boon for Windows.

Perl Substr
5 direct replies — Read more / Contribute
by lddzjwwy
on Jun 18, 2013 at 11:32

    Hi monks,

    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?

    Thanks a lot!

DBD::Sybase query execute hangs randomly for Sybase IQ 15.4
3 direct replies — Read more / Contribute
by cmahajan
on Jun 18, 2013 at 09:36
    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.
Editing text file
3 direct replies — Read more / Contribute
by freekngeek
on Jun 18, 2013 at 07:43

    Hi, All

    I have text file which looks like this

    *|DSPF 1.0 * *|DESIGN "TOP_1b_1a" *|DATE "Tue Jun 18 11:42:12 2013" *|VENDOR "Mentor Graphics Corp." *|PROGRAM "Calibre xRC v2012.2_36.25" *|DIVIDER / *|DELIMITER : * Nominal Temperature: 25C * Circuit Temperature: 25C * .subckt TOP_1b_1a PC_M1_M2_50_500_50_500_50_500_50_500_50_bot + PC_M1_M2_50_100_50_100_50_100_50_100_50_bot + PC_M1_M2_500_250_500_250_500_250_500_250_500_ctr * PC_M1_M2_500_250_500_250_500_250_500_250_500_low + PC_M1_M2_75_500_75_500_75_500_75_500_75_bot + PC_M1_M2_75_100_75_100_75_100_75_100_75_bot * PC_M1_M2_150_50_150_50_150_50_150_50_150_high + PC_M1_M2_100_500_100_500_100_500_100_500_100_bot + PC_M1_M2_100_100_100_100_100_100_100_100_100_bot rM6_M7_JA_50_100_50_100_50_100_50_100_50_ctr/0 R435:pos + M6_M7_JA_50_100_50_100_50_100_50_100_50_ctr 238.22 rM6_M7_JA_50_100_50_100_50_100_50_100_50_ctr/1 R434:neg + M6_M7_JA_50_100_50_100_50_100_50_100_50_ctr 238.22 * *|NET M6_M7_JA_50_100_50_100_50_100_50_100_50_high 0.0 *|I (R435:neg R435 neg B 0.0 10 3151) R0 R0:pos R0:neg lvsres R=0.001 $X=9.975 $Y=10.999 R1 R1:pos R1:neg lvsres R=0.001 $X=9.975 $Y=122 R2 R2:pos R2:neg lvsres R=0.001 $X=9.975 $Y=243.999 R3 R3:pos R3:neg lvsres R=0.001 $X=9.975 $Y=355 R4 R4:pos R4:neg lvsres R=0.001 $X=159.963 $Y=10.999 R5 R5:pos R5:neg lvsres R=0.001 $X=159.963 $Y=122
    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

Composite Charset Data to UTF8?
2 direct replies — Read more / Contribute
by perlig
on Jun 18, 2013 at 06:21
    Dear omniscient monks,

    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?!

    kindly perlig

    $perlig =~ s/pec/cep/g if 'errors expected';
Create a Hash Dynamically and add the values of same key
4 direct replies — Read more / Contribute
by rahulruns
on Jun 18, 2013 at 05:32

    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
Using __DATA__ from a package
4 direct replies — Read more / Contribute
by yoda54
on Jun 17, 2013 at 22:19
    Monks,

    How would do I access local __DATA__ inside a package?

    Thanks

    package Test; sub run { while(<Test::DATA>) { print "$_\n"; } } __DATA__ 1 #!/usr/bin/perl use strict; use warnings; use Test; Test::run();
Installing modules
7 direct replies — Read more / Contribute
by slugger415
on Jun 17, 2013 at 18:32

    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?

    Thank you as always...

Unit testing question with Test::Deep
1 direct reply — Read more / Contribute
by willjones
on Jun 17, 2013 at 16:20
    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' );
Smart matching is experimental/depreciated in 5.18 - recommendations?
7 direct replies — Read more / Contribute
by coolmichael
on Jun 17, 2013 at 15:39

    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.

    Mostly the given/whens look like this:

    given($foo) { when('abc') {...} when(['foo', 'bar']) {...} default {...} };

Add your question
Title:
Your question:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":


  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (22)
    As of 2013-06-19 13:05 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How many continents have you visited?









      Results (655 votes), past polls